-
Notifications
You must be signed in to change notification settings - Fork 83
fix: allow arbitrary attributes on script tags without type errors #630
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
Open
harlan-zw
wants to merge
3
commits into
main
Choose a base branch
from
fix/292-arbitrary-script-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9
β9
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forward custom attrs through the Partytown path.
After widening
input, theoptions.partytownbranch still emits only{ src, type: 'text/partytown' }, so arbitrary attrs liketw-client-keyβand existing fields likenonceβare silently dropped there. That leaves this fix incomplete for Partytown users.Suggested change
π€ Prompt for AI Agents
π§© Analysis chain
π Script executed:
Repository: nuxt/scripts
Length of output: 12564
π Script executed:
Repository: nuxt/scripts
Length of output: 2632
π Script executed:
# Find the git diff to see what changed in these files git diff HEAD~1 src/runtime/types.ts src/runtime/composables/useScript.tsRepository: nuxt/scripts
Length of output: 244
π Script executed:
Repository: nuxt/scripts
Length of output: 7698
π Script executed:
Repository: nuxt/scripts
Length of output: 1682
π Script executed:
Repository: nuxt/scripts
Length of output: 172
π Script executed:
Repository: nuxt/scripts
Length of output: 4435
π Script executed:
Repository: nuxt/scripts
Length of output: 374
π Script executed:
Repository: nuxt/scripts
Length of output: 1237
π Script executed:
Repository: nuxt/scripts
Length of output: 4017
π Script executed:
# Let's verify if the string branch exists in UseScriptInput by checking unhead docs web_searchRepository: nuxt/scripts
Length of output: 106
π Web query:
@unhead/vue UseScriptInput type definition structureπ‘ Result:
In
@unhead/vue(v2.1.4),UseScriptInputis defined as:[1]
So you can pass either:
srcURL (e.g.useScript('https://β¦/sdk.js')). [1]src: string(required)<script>fields from Unheadβs script schema (minussrc), plus Unheaddata-*keys / schema augmentations, etc.ResolvableProperties<T>(i.e., values can be plain values,Ref,ComputedRef, or a getter function). [1][2]ResolvablePropertiesis (simplified) mapped as:and
ResolvableValue<T>includesT | (() => T) | Ref<T> | ComputedRef<T>(plus falsy allowances). [2]Example
[1][2]
Sources:
@unhead/vue/dist/scripts.d.mts(UseScriptInput) [1],@unhead/vue/dist/shared/vue.DoxLTFJk.d.mts(ResolvableProperties/ResolvableValue) [2].π Script executed:
Repository: nuxt/scripts
Length of output: 489
π Script executed:
Repository: nuxt/scripts
Length of output: 387
Preserve bare-string
useScript()calls in the type signature.The
NuxtUseScriptInputtype definition narrows away thestringbranch fromUseScriptInput. In TypeScript, the intersection(string | Object) & Record<string & {}, any>distributes to(string & Record<string & {}, any>) | (Object & Record<string & {}, any>), and sincestringcannot intersect with an object type, thestringbranch is eliminated. This breaks all existinguseScript('https://...')calls at compile time, even though the runtime at line 36 still normalizes string input. The pattern is widely used throughout tests and documentation.Explicitly preserve the string union in
NuxtUseScriptInput:Suggested fix in
src/runtime/types.tsπ€ Prompt for AI Agents