Skip to content

Commit

Permalink
simpler approach
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Oct 24, 2024
1 parent 89dd0c0 commit d6c2d43
Showing 1 changed file with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ let reloading = false
let startLatency: number | null = null

let pendingHotUpdateWebpack = Promise.resolve()
let pendingFastRefresh = Promise.resolve()
let resolvePendingHotUpdateWebpack: () => void = () => {}
let resolvePendingFastRefresh: () => void = () => {}
function setPendingHotUpdateWebpack() {
pendingHotUpdateWebpack = new Promise((resolve) => {
resolvePendingHotUpdateWebpack = () => {
Expand All @@ -66,14 +64,6 @@ function setPendingHotUpdateWebpack() {
})
}

function setPendingFastRefresh() {
pendingFastRefresh = new Promise((resolve) => {
resolvePendingFastRefresh = () => {
resolve()
}
})
}

export function waitForWebpackRuntimeHotUpdate() {
return pendingHotUpdateWebpack
}
Expand All @@ -93,7 +83,6 @@ function handleSuccessfulHotUpdateWebpack(
updatedModules: ReadonlyArray<string>
) {
resolvePendingHotUpdateWebpack()
resolvePendingFastRefresh()
dispatcher.onBuildOk()
reportHmrLatency(sendMessage, updatedModules)

Expand Down Expand Up @@ -440,6 +429,7 @@ function processMessage(
)

if (obj.action === HMR_ACTIONS_SENT_TO_BROWSER.BUILT) {
// Handle hot updates
handleHotUpdate()
}
return
Expand Down Expand Up @@ -481,9 +471,6 @@ function processMessage(
reloading = true
return window.location.reload()
}

setPendingFastRefresh()

startTransition(() => {
router.hmrRefresh()
dispatcher.onRefresh()
Expand Down Expand Up @@ -544,12 +531,7 @@ export default function HotReload({
const dispatcher = useMemo<Dispatcher>(() => {
return {
onBuildOk() {
// If fast refresh is triggered and causes server errors and then BUILT action
// comes in after, we'll be resetting the errors that were set by the refresh action.
// We make sure that the refresh action finished before applying the update
pendingFastRefresh.then(() => {
dispatch({ type: ACTION_BUILD_OK })
})
dispatch({ type: ACTION_BUILD_OK })
},
onBuildError(message) {
dispatch({ type: ACTION_BUILD_ERROR, message })
Expand Down

0 comments on commit d6c2d43

Please sign in to comment.