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

edge: use JSON parse instead of inlining the manifests objects #50960

Merged
Merged
8 changes: 6 additions & 2 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,9 @@ export default async function build(
)
await promises.writeFile(
path.join(distDir, PRERENDER_MANIFEST).replace(/\.json$/, '.js'),
`self.__PRERENDER_MANIFEST=${JSON.stringify(prerenderManifest)}`,
`self.__PRERENDER_MANIFEST=${JSON.stringify(
JSON.stringify(prerenderManifest)
)}`,
'utf8'
)
await generateClientSsgManifest(prerenderManifest, {
Expand All @@ -2953,7 +2955,9 @@ export default async function build(
)
await promises.writeFile(
path.join(distDir, PRERENDER_MANIFEST).replace(/\.json$/, '.js'),
`self.__PRERENDER_MANIFEST=${JSON.stringify(prerenderManifest)}`,
`self.__PRERENDER_MANIFEST=${JSON.stringify(
JSON.stringify(prerenderManifest)
)}`,
'utf8'
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,20 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
: 'const incrementalCacheHandler = null'
}

const maybeJSONParse = (str) => str ? JSON.parse(str) : undefined
feedthejim marked this conversation as resolved.
Show resolved Hide resolved

const buildManifest = self.__BUILD_MANIFEST
const prerenderManifest = self.__PRERENDER_MANIFEST
const reactLoadableManifest = self.__REACT_LOADABLE_MANIFEST
const rscManifest = self.__RSC_MANIFEST
const rscCssManifest = self.__RSC_CSS_MANIFEST
const rscServerManifest = self.__RSC_SERVER_MANIFEST
const prerenderManifest = maybeJSONParse(self.__PRERENDER_MANIFEST)
const reactLoadableManifest = maybeJSONParse(self.__REACT_LOADABLE_MANIFEST)
const rscManifest = maybeJSONParse(self.__RSC_MANIFEST)
const rscCssManifest = maybeJSONParse(self.__RSC_CSS_MANIFEST)
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST)
const subresourceIntegrityManifest = ${
sriEnabled ? 'self.__SUBRESOURCE_INTEGRITY_MANIFEST' : 'undefined'
sriEnabled
? 'maybeJSONParse(self.__SUBRESOURCE_INTEGRITY_MANIFEST)'
: 'undefined'
}
const nextFontManifest = self.__NEXT_FONT_MANIFEST
const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)

const render = getRender({
pagesType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export class ClientReferenceEntryPlugin {
) as unknown as webpack.sources.RawSource
assets[`${this.assetPrefix}${FLIGHT_SERVER_CSS_MANIFEST}.js`] =
new sources.RawSource(
'self.__RSC_CSS_MANIFEST=' + manifest
`self.__RSC_CSS_MANIFEST=${JSON.stringify(manifest)}`
) as unknown as webpack.sources.RawSource
}
)
Expand Down Expand Up @@ -990,7 +990,7 @@ export class ClientReferenceEntryPlugin {

assets[`${this.assetPrefix}${SERVER_REFERENCE_MANIFEST}.js`] =
new sources.RawSource(
'self.__RSC_SERVER_MANIFEST=' + json
`self.__RSC_SERVER_MANIFEST=${JSON.stringify(json)}`
) as unknown as webpack.sources.RawSource
assets[`${this.assetPrefix}${SERVER_REFERENCE_MANIFEST}.json`] =
new sources.RawSource(json) as unknown as webpack.sources.RawSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export class ClientReferenceManifestPlugin {
pluginState.ASYNC_CLIENT_MODULES = []

assets[file + '.js'] = new sources.RawSource(
'self.__RSC_MANIFEST=' + json
`self.__RSC_MANIFEST=${JSON.stringify(json)}`
// Work around webpack 4 type of RawSource being used
// TODO: use webpack 5 type by default
) as unknown as webpack.sources.RawSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ export class NextFontManifestPlugin {
}
}

const manifest = JSON.stringify(nextFontManifest, null, 2)
const manifest = JSON.stringify(nextFontManifest, null)
// Create manifest for edge
assets[`server/${NEXT_FONT_MANIFEST}.js`] = new sources.RawSource(
`self.__NEXT_FONT_MANIFEST=${manifest}`
`self.__NEXT_FONT_MANIFEST=${JSON.stringify(manifest)}`
)
// Create manifest for server
assets[`server/${NEXT_FONT_MANIFEST}.json`] = new sources.RawSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ export class ReactLoadablePlugin {
)
if (this.runtimeAsset) {
assets[this.runtimeAsset] = new sources.RawSource(
`self.__REACT_LOADABLE_MANIFEST=${JSON.stringify(manifest)}`
`self.__REACT_LOADABLE_MANIFEST=${JSON.stringify(
JSON.stringify(manifest)
)}`
)
}
return assets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SubresourceIntegrityPlugin {
const json = JSON.stringify(hashes, null, 2)
const file = 'server/' + SUBRESOURCE_INTEGRITY_MANIFEST
assets[file + '.js'] = new sources.RawSource(
'self.__SUBRESOURCE_INTEGRITY_MANIFEST=' + json
`self.__SUBRESOURCE_INTEGRITY_MANIFEST=${JSON.stringify(json)}`
// Work around webpack 4 type of RawSource being used
// TODO: use webpack 5 type by default
) as unknown as webpack.sources.RawSource
Expand Down