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

Add additional layer for server components case #36921

Merged
merged 10 commits into from
May 16, 2022
5 changes: 4 additions & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ export function getViewsEntry(opts: {
viewsDir: string
pageExtensions: string[]
}) {
return `next-view-loader?${stringify(opts)}!`
return {
import: `next-view-loader?${stringify(opts)}!`,
layer: 'sc_server',
}
}

export function getServerlessEntry(opts: {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/webpack/loaders/next-view-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ const nextViewLoader: webpack.LoaderDefinitionFunction<{
export const components = {
${componentsCode.join(',\n')}
};

export const webpackRequire = __webpack_require__
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
`
return result
}
Expand Down
7 changes: 4 additions & 3 deletions packages/next/server/view-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ function createServerComponentRenderer(
) {
// We need to expose the `__webpack_require__` API globally for
// react-server-dom-webpack. This is a hack until we find a better way.
if (ComponentMod.__next_rsc__) {
if (ComponentMod.webpackRequire || ComponentMod.__next_rsc__) {
// @ts-ignore
globalThis.__webpack_require__ =
ComponentMod.__next_rsc__.__webpack_require__
globalThis.__webpack_require__ = ComponentMod.webpackRequire
? ComponentMod.webpackRequire
: ComponentMod.__next_rsc__.__webpack_require__

// @ts-ignore
globalThis.__webpack_chunk_load__ = () => Promise.resolve()
Expand Down