Skip to content

Commit

Permalink
Revert "fix hmr event, and avoid RSC fetch on any message" (#58452)
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner authored Nov 14, 2023
1 parent 1ee50b8 commit d6f1d94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@ function processMessage(
})
)

if (!process.env.TURBOPACK) {
const isHotUpdate =
obj.action !== HMR_ACTIONS_SENT_TO_BROWSER.SYNC &&
(!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') &&
isUpdateAvailable()

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
handleHotUpdate()
}
const isHotUpdate =
obj.action !== HMR_ACTIONS_SENT_TO_BROWSER.SYNC &&
(!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') &&
isUpdateAvailable()

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
handleHotUpdate()
}
return
}
Expand All @@ -370,6 +368,13 @@ function processMessage(
dispatcher.onRefresh()
})

if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB()
self.__NEXT_HMR_CB = null
}
}

return
}
case HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE: {
Expand Down Expand Up @@ -444,16 +449,6 @@ export default function HotReload({
}
}, [dispatch])

useEffect(() => {
if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB()
self.__NEXT_HMR_CB = null
}
}
// currentHmrObj will change when ACTION_REFRESH is dispatched.
}, [state.currentHmrObj])

const handleOnUnhandledError = useCallback((error: Error): void => {
// Component stack is added to the error in use-error-handler in case there was a hydration errror
const componentStack = (error as any)._componentStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const ACTION_UNHANDLED_REJECTION = 'unhandled-rejection'
export const ACTION_VERSION_INFO = 'version-info'
export const INITIAL_OVERLAY_STATE: OverlayState = {
nextId: 1,
currentHmrObj: {},
buildError: null,
errors: [],
notFound: false,
Expand Down Expand Up @@ -61,7 +60,6 @@ export type FastRefreshState =
}

export interface OverlayState {
currentHmrObj: {}
nextId: number
buildError: string | null
errors: SupportedErrorEvent[]
Expand Down Expand Up @@ -111,9 +109,6 @@ export const errorOverlayReducer: React.Reducer<
case ACTION_REFRESH: {
return {
...state,
// Create a new hmrObj to track when a HMR was applied, this ensures the HMR callback `useEffect` will be called.
// Uses an object as the identity is unique, so anytime it changes it will trigger a new run of the effect.
currentHmrObj: {},
buildError: null,
errors:
// Errors can come in during updates. In this case, UNHANDLED_ERROR
Expand Down

0 comments on commit d6f1d94

Please sign in to comment.