From 9fdfcf2a87158bd85c088806511c323642f3e431 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Tue, 14 Nov 2023 10:40:08 -0800 Subject: [PATCH] Revert "fix hmr event, and avoid RSC fetch on any message (#58403)" This reverts commit 21480779e00b0f765249730854f56796b8ee037c. --- .../react-dev-overlay/hot-reloader-client.tsx | 35 ++++++++----------- .../internal/error-overlay-reducer.ts | 5 --- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/next/src/client/components/react-dev-overlay/hot-reloader-client.tsx b/packages/next/src/client/components/react-dev-overlay/hot-reloader-client.tsx index ea809ab10ce2f..01e7f8dda40a7 100644 --- a/packages/next/src/client/components/react-dev-overlay/hot-reloader-client.tsx +++ b/packages/next/src/client/components/react-dev-overlay/hot-reloader-client.tsx @@ -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 } @@ -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: { @@ -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 diff --git a/packages/next/src/client/components/react-dev-overlay/internal/error-overlay-reducer.ts b/packages/next/src/client/components/react-dev-overlay/internal/error-overlay-reducer.ts index e4aa340a3450e..4536a263277e4 100644 --- a/packages/next/src/client/components/react-dev-overlay/internal/error-overlay-reducer.ts +++ b/packages/next/src/client/components/react-dev-overlay/internal/error-overlay-reducer.ts @@ -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, @@ -61,7 +60,6 @@ export type FastRefreshState = } export interface OverlayState { - currentHmrObj: {} nextId: number buildError: string | null errors: SupportedErrorEvent[] @@ -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