MCPcopy
hub / github.com/vercel/next.js / scheduleUpdate

Function scheduleUpdate

packages/react-refresh-utils/internal/helpers.ts:156–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

154var isUpdateScheduled: boolean = false
155// This function aggregates updates from multiple modules into a single React Refresh call.
156function scheduleUpdate() {
157 if (isUpdateScheduled) {
158 return
159 }
160 isUpdateScheduled = true
161
162 function canApplyUpdate(status: ModuleHotStatus) {
163 return status === 'idle'
164 }
165
166 function applyUpdate() {
167 isUpdateScheduled = false
168 try {
169 RefreshRuntime.performReactRefresh()
170 } catch (err) {
171 console.warn(
172 'Warning: Failed to re-render. We will retry on the next Fast Refresh event.\n' +
173 err
174 )
175 }
176 }
177
178 if (canApplyUpdate(module.hot.status())) {
179 // Apply update on the next tick.
180 Promise.resolve().then(() => {
181 applyUpdate()
182 })
183 return
184 }
185
186 const statusHandler = (status) => {
187 if (canApplyUpdate(status)) {
188 module.hot.removeStatusHandler(statusHandler)
189 applyUpdate()
190 }
191 }
192
193 // Apply update once the HMR runtime's status is idle.
194 module.hot.addStatusHandler(statusHandler)
195}
196
197// Needs to be compatible with IE11
198export default {

Callers

nothing calls this directly

Calls 5

canApplyUpdateFunction · 0.85
thenMethod · 0.80
applyUpdateFunction · 0.70
resolveMethod · 0.65
statusMethod · 0.45

Tested by

no test coverage detected