Repository navigation
Conversation
Serialize the values embedded in the generated server manifests with `JSON.stringify`, so a prerendered route such as `ssg/customer's-choice` no longer produces an invalid manifest.
There was a problem hiding this comment.
Code Review
This pull request ensures that asset paths, base hrefs, and other manifest values are safely serialized using JSON.stringify instead of direct interpolation, preventing syntax errors when these values contain JavaScript string delimiters like single quotes. Unit and end-to-end tests have been added to verify this behavior. Feedback is provided on the test helper evaluateManifest to use a more robust regular expression when replacing 'export default', preventing accidental replacements if that substring appears within serialized content.
| function evaluateManifest(manifestContent: string): unknown { | ||
| return new Function(manifestContent.replace('export default', 'return'))(); | ||
| } |
There was a problem hiding this comment.
Using a simple string replacement manifestContent.replace('export default', 'return') will replace the first occurrence of 'export default'. If any serialized asset paths, routes, or other content in the manifest happen to contain the substring 'export default', the replacement will occur there instead of the actual export statement, leading to syntax or evaluation errors. Using a regular expression with the multiline flag (/m) and anchoring to the start of the line (^) makes this replacement much more robust.
function evaluateManifest(manifestContent: string): unknown {\n return new Function(manifestContent.replace(/^\\s*export default/m, 'return'))();\n }
Backport of #34493