Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race with hot-reloader-client clearing overlay errors #71771

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
simpler approach
  • Loading branch information
ztanner committed Oct 24, 2024
commit d6c2d438017d7e7c8e88bed86fcae6c8fd77d3d4
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
Loading