diff options
author | 2022-04-06 06:15:18 -0700 | |
---|---|---|
committer | 2022-04-06 06:15:18 -0700 | |
commit | 795c172d9ea75895c749c492cc98fce2f636e05d (patch) | |
tree | fdaddbb922a4739d00da5664561f08a9656da76b | |
parent | cfe60996c2d9f3b69bf1de92e1106bab5454af79 (diff) | |
download | bun-795c172d9ea75895c749c492cc98fce2f636e05d.tar.gz bun-795c172d9ea75895c749c492cc98fce2f636e05d.tar.zst bun-795c172d9ea75895c749c492cc98fce2f636e05d.zip |
Support newer next
-rw-r--r-- | packages/bun-framework-next/renderDocument.tsx | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/packages/bun-framework-next/renderDocument.tsx b/packages/bun-framework-next/renderDocument.tsx index 42e988b88..1bf2086f9 100644 --- a/packages/bun-framework-next/renderDocument.tsx +++ b/packages/bun-framework-next/renderDocument.tsx @@ -109,19 +109,31 @@ function getScripts(files: DocumentFiles) { const normalScripts = files?.allFiles?.filter(isJSFile) ?? []; const lowPriorityScripts = buildManifest?.lowPriorityFiles?.filter(isJSFile) ?? []; + var entryPointIndex = -1; + const scripts = [...normalScripts, ...lowPriorityScripts].map( + (file, index) => { + if (file.includes(".entry.")) { + entryPointIndex = index; + } - return [...normalScripts, ...lowPriorityScripts].map((file) => { - return ( - <script - key={file} - src={`${encodeURI(file)}${devOnlyCacheBusterQueryString}`} - nonce={props.nonce} - async - crossOrigin={props.crossOrigin || process.env.__NEXT_CROSS_ORIGIN} - type="module" - /> - ); - }); + return ( + <script + key={file} + src={`${encodeURI(file)}${devOnlyCacheBusterQueryString}`} + nonce={props.nonce} + async + crossOrigin={props.crossOrigin || process.env.__NEXT_CROSS_ORIGIN} + type="module" + /> + ); + } + ); + if (entryPointIndex > 0) { + const entry = scripts.splice(entryPointIndex, 1); + scripts.unshift(...entry); + } + + return scripts; } interface DomainLocale { @@ -357,17 +369,28 @@ function enhanceComponents( : Component, }; } - -Object.defineProperty(NextDocument.Head.prototype, "getScripts", { +const scriptsGetter = { get() { return getScripts; }, -}); -Object.defineProperty(NextDocument.NextScript.prototype, "getScripts", { - get() { - return getScripts; - }, -}); +}; + +Object.defineProperty(NextDocument.Head.prototype, "getScripts", scriptsGetter); +Object.defineProperty( + NextDocument.NextScript.prototype, + "getScripts", + scriptsGetter +); +try { + Object.defineProperty( + NextDocument.default.prototype, + "getScripts", + scriptsGetter + ); +} catch {} +try { + Object.defineProperty(NextDocument.default, "getScripts", scriptsGetter); +} catch {} export async function render({ route, @@ -764,7 +787,7 @@ export async function render({ }, // Only enabled in production as development mode has features relying on HMR (style injection for example) // @ts-expect-error - unstable_runtimeJS: false, + unstable_runtimeJS: true, // process.env.NODE_ENV === "production" // ? pageConfig.unstable_runtimeJS // : undefined, |