From d488997fe19533bd9b77ef4b24255dd45e0596d0 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 23 Jun 2023 22:23:13 +0200 Subject: [PATCH 1/2] fix createServerReference build --- .../next-flight-loader/action-client-wrapper.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts index 8d490e11c26ee..d373f5c4ddd2d 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts @@ -1,12 +1,20 @@ // This file must be bundled in the app's client layer, it shouldn't be directly // imported by the server. -// eslint-disable-next-line import/no-extraneous-dependencies -import { createServerReference } from 'react-server-dom-webpack/client' import { callServer } from 'next/dist/client/app-call-server' // A noop wrapper to let the Flight client create the server reference. // See also: https://github.com/facebook/react/pull/26632 export default function (id: string) { + // Since we're using the Edge build of Flight client for SSR [1], here we need to + // also use the same Edge build to create the reference. For the client bundle, + // we use the default and let Webpack to resolve it to the correct version. + // 1: https://github.com/vercel/next.js/blob/16eb80b0b0be13f04a6407943664b5efd8f3d7d0/packages/next/src/server/app-render/use-flight-response.tsx#L24-L26 + const { createServerReference } = ( + typeof window === 'undefined' + ? require('react-server-dom-webpack/client.edge') + : require('react-server-dom-webpack/client') + ) as typeof import('react-server-dom-webpack/client') + return createServerReference(id, callServer) } From 169c25726174ae3d8de59d1d4c11861b586bc3ce Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 23 Jun 2023 23:06:12 +0200 Subject: [PATCH 2/2] fix lint error --- .../loaders/next-flight-loader/action-client-wrapper.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts index d373f5c4ddd2d..76abdb0488074 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts @@ -12,8 +12,10 @@ export default function (id: string) { // 1: https://github.com/vercel/next.js/blob/16eb80b0b0be13f04a6407943664b5efd8f3d7d0/packages/next/src/server/app-render/use-flight-response.tsx#L24-L26 const { createServerReference } = ( typeof window === 'undefined' - ? require('react-server-dom-webpack/client.edge') - : require('react-server-dom-webpack/client') + ? // eslint-disable-next-line import/no-extraneous-dependencies + require('react-server-dom-webpack/client.edge') + : // eslint-disable-next-line import/no-extraneous-dependencies + require('react-server-dom-webpack/client') ) as typeof import('react-server-dom-webpack/client') return createServerReference(id, callServer)