Skip to content

Commit

Permalink
Lazily require react-server-dom-webpack in next-flight-loader
Browse files Browse the repository at this point in the history
Testing if this unblocks sync.
  • Loading branch information
eps1lon committed Oct 9, 2024
1 parent 355b3f5 commit 54097c1
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ export { findSourceMapURL } from 'next/dist/client/app-find-source-map-url'
// 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
export const createServerReference = (
(!!process.env.NEXT_RUNTIME
? // 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')
).createServerReference
// TODO: Figure out why we can't just eagerly require `react-serer-dom-webpack/client` here.
export function createServerReference(
id: string,
callServer: unknown,
encodeFormAction: unknown,
findSourceMapURL: unknown,
functionName: unknown
) {
// 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: createServerReferenceImpl } = (
!!process.env.NEXT_RUNTIME
? // 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 createServerReferenceImpl(id, callServer, encodeFormAction, findSourceMapURL, functionName)
}

0 comments on commit 54097c1

Please sign in to comment.