-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: head duplication when binding is present #9124
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a23277
chore: render head output in playground
gtm-nayan a1e60a3
add tests
gtm-nayan cfdc519
fix head duplication with binding present
gtm-nayan f0e1f69
changeset
gtm-nayan adea603
Merge branch 'master' into fix-binding-head-duplicate
gtm-nayan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: head duplication when binding is present |
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
3 changes: 3 additions & 0 deletions
3
...ages/svelte/test/server-side-rendering/samples/head-no-duplicates-with-binding/Foo.svelte
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
export let bar = null | ||
</script> |
2 changes: 2 additions & 0 deletions
2
...te/test/server-side-rendering/samples/head-no-duplicates-with-binding/_expected-head.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<link rel="canonical" href="/test"> | ||
<meta name="description" content="test"> |
Empty file.
11 changes: 11 additions & 0 deletions
11
...ges/svelte/test/server-side-rendering/samples/head-no-duplicates-with-binding/main.svelte
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
import Foo from './Foo.svelte'; | ||
let bar; | ||
</script> | ||
|
||
<svelte:head> | ||
<link rel="canonical" href="/test" /> | ||
<meta name="description" content="test" /> | ||
</svelte:head> | ||
|
||
<Foo bind:bar /> |
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.
Still don't fully understand the fix - how is the binding mutating the head?
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.
Binding doesn't mutate it, but the emitted code is like
so if the loop isn't settled in one go, the next iteration will add the head contents again and so on
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.
Oh I see - I guess it makes sense then to only use the first head. Can there ever be a situation where this would prevent other head elements from showing up? Like, if there's some component inside an if block that contains a head element, will that be part of the first loop already?
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.
Should be fine, the child component inside the if will get reexecuted after resetting the head
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.
So what constitutes to a rerun then? Only bindings? TBH I never looked into that part of the code base much. I just want to rule out that we don't lose head content that would otherwise be rightfully added.
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.
svelte/packages/svelte/src/compiler/compile/render_ssr/index.js
Line 143 in adea603
Looks like it's only bindings