Created
December 23, 2024 06:13
-
-
Save Innei/e0ae522b7948dfbe3407d139de0b7d8b to your computer and use it in GitHub Desktop.
patch next@v14 ssr render issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dist/build/webpack/loaders/next-flight-loader/index.js b/dist/build/webpack/loaders/next-flight-loader/index.js | |
index 34d196104da9e95a5d6d6202cc4739b10b3922e3..1c2d9faa02c8de84d0a18fa800ac6c6a1f69c174 100644 | |
--- a/dist/build/webpack/loaders/next-flight-loader/index.js | |
+++ b/dist/build/webpack/loaders/next-flight-loader/index.js | |
@@ -57,6 +57,8 @@ function transformSource(source, sourceMap) { | |
if (typeof source !== "string") { | |
throw new Error("Expected source to have been transformed to a string."); | |
} | |
+ const options = this.getOptions() | |
+ const { isEdgeServer } = options | |
// Assign the RSC meta information to buildInfo. | |
// Exclude next internal files which are not marked as client files | |
const buildInfo = (0, _getmodulebuildinfo.getModuleBuildInfo)(this._module); | |
@@ -88,22 +90,22 @@ function transformSource(source, sourceMap) { | |
return; | |
} | |
let esmSource = `\ | |
-import { createProxy } from "${MODULE_PROXY_PATH}" | |
-`; | |
- let cnt = 0; | |
- for (const ref of clientRefs){ | |
- if (ref === "") { | |
- esmSource += `\nexports[''] = createProxy(String.raw\`${resourceKey}#\`);`; | |
- } else if (ref === "default") { | |
- esmSource += `\ | |
-export default createProxy(String.raw\`${resourceKey}#default\`); | |
-`; | |
- } else { | |
- esmSource += ` | |
-const e${cnt} = createProxy(String.raw\`${resourceKey}#${ref}\`); | |
-export { e${cnt++} as ${ref} };`; | |
- } | |
- } | |
+ import { createProxy } from "${MODULE_PROXY_PATH}" | |
+ const proxy = ${ | |
+ isEdgeServer ? '' : 'await' | |
+ } createProxy(String.raw\`${resourceKey}\`) | |
+ ` | |
+ let cnt = 0 | |
+ for (const ref of clientRefs) { | |
+ if (ref === '') { | |
+ esmSource += `exports[''] = proxy['']\n` | |
+ } else if (ref === 'default') { | |
+ esmSource += `export default proxy.default;\n` | |
+ } else { | |
+ esmSource += `const e${cnt} = proxy["${ref}"];\n` | |
+ esmSource += `export { e${cnt++} as ${ref} };\n` | |
+ } | |
+ } | |
this.callback(null, esmSource, sourceMap); | |
return; | |
} | |
diff --git a/dist/build/webpack-config.js b/dist/build/webpack-config.js | |
index d45ca001c5e8c2f94319448a0b642daac1334bd4..1f7f9c947581fd95bd82a792a345e4c99bfb59d1 100644 | |
--- a/dist/build/webpack-config.js | |
+++ b/dist/build/webpack-config.js | |
@@ -417,6 +417,12 @@ async function getBaseWebpackConfig(dir, { buildId, encryptionKey, config, compi | |
const defaultLoaders = { | |
babel: useSWCLoader ? swcDefaultLoader : babelLoader | |
}; | |
+ const nextFlightLoader = { | |
+ loader: 'next-flight-loader', | |
+ options: { | |
+ isEdgeServer, | |
+ }, | |
+ } | |
const appServerLayerLoaders = hasAppDir ? [ | |
// When using Babel, we will have to add the SWC loader | |
// as an additional pass to handle RSC correctly. | |
@@ -426,6 +432,7 @@ async function getBaseWebpackConfig(dir, { buildId, encryptionKey, config, compi | |
babelLoader | |
].filter(Boolean) : []; | |
const instrumentLayerLoaders = [ | |
+ nextFlightLoader, | |
// When using Babel, we will have to add the SWC loader | |
// as an additional pass to handle RSC correctly. | |
// This will cause some performance overhead but | |
@@ -433,7 +440,7 @@ async function getBaseWebpackConfig(dir, { buildId, encryptionKey, config, compi | |
swcServerLayerLoader, | |
babelLoader | |
].filter(Boolean); | |
- const middlewareLayerLoaders = [ | |
+ const middlewareLayerLoaders = [nextFlightLoader, | |
// When using Babel, we will have to use SWC to do the optimization | |
// for middleware to tree shake the unused default optimized imports like "next/server". | |
// This will cause some performance overhead but | |
@@ -1095,9 +1102,7 @@ async function getBaseWebpackConfig(dir, { buildId, encryptionKey, config, compi | |
isEdgeServer | |
}) | |
}, | |
- use: { | |
- loader: "next-flight-loader" | |
- } | |
+ use: nextFlightLoader, | |
} | |
] : [], | |
// TODO: FIXME: do NOT webpack 5 support with this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment