Conversation
`useRegistryScript` used `Object.assign` to merge the registry-defined `scriptOptions` (which include `use` / `beforeInit` functions) into `userOptions.scriptOptions`. When the user configured the script in `nuxt.config`, `userOptions.scriptOptions` was a reference to `runtimeConfig.public.scripts.<key>.scriptOptions`, so the merge wrote function references directly into `runtimeConfig`. During prerender, `uneval(ssrContext.config)` then failed with "Cannot stringify a function". Switch the two merges to `defu` / spread so a fresh object is produced and `runtimeConfig` stays serializable. Fixes #702
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #702 —
Cannot stringify a functionduring prerender when a script is configured inscripts.registryinnuxt.config.Root cause
useRegistryScriptinsrc/runtime/utils.tsusedObject.assignto merge the registry-definedscriptOptions(which include the composable'suse()function) intouserOptions.scriptOptions. When the user configured the script vianuxt.config,userOptions.scriptOptionswas a live reference toruntimeConfig.public.scripts.<key>.scriptOptions. The merge therefore wrote a function reference directly intoruntimeConfig. The wrappedbeforeInitfunction was then assigned to the same reference.At prerender time, Nuxt's
renderPayloadJsonScriptcallsuneval(ssrContext.config)which walks the public runtime config; devalue throws when it encounters theuse/beforeInitfunctions that leaked in.Fix
Switch the two merges to
defu/ spread so they produce fresh objects and leaveruntimeConfiguntouched. This matches the v1 behavior (already fixed there).Test plan
test/unit/utils.test.tsthat asserts the runtime config object passed viauseRuntimeConfig().public.scripts.<key>is not mutated byuseRegistryScript. The test fails on current 0.x and passes with this fix.pnpm test:unit).cloudflareWebAnalyticswithscriptOptions: { trigger: 'client' }inscripts.registrynow prerenders cleanly.