-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: svelte head body separation for nested components in <svelte:head> tag #17324
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
Closed
+121
−237
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6e5d254
fix: separate head and body content in svelte:head blocks
fabhari 20765d2
test cases for header
fabhari 5814090
dev : supported nested component in svelte:head tag , non head tags a…
e8f6c10
Merge branch 'main' into fix/svelte-head-body-separation
fabhari 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 | ||
| --- | ||
|
|
||
| support nested components in <svelte:head> |
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
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-browser/samples/head-nested-body-separation/Child.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,5 @@ | ||
| <svelte:head> | ||
| <meta name="child-data" content="value" /> | ||
| </svelte:head> | ||
|
|
||
| <p>Child body</p> |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-browser/samples/head-nested-body-separation/_config.js
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,24 @@ | ||
| import { test } from '../../assert'; | ||
|
|
||
| export default test({ | ||
| async test({ assert, target }) { | ||
| // Test 1: Verify body content appears in body, not head | ||
| const mainContent = target.querySelector('main'); | ||
| assert.ok(mainContent, 'Main element should exist in body'); | ||
| assert.equal(mainContent?.textContent, 'Main content'); | ||
|
|
||
| // Test 2: Verify head contains meta tag (head-specific) | ||
| const metaTag = document.head.querySelector('meta[name="child-data"]'); | ||
| assert.ok(metaTag, 'Meta tag should be in head'); | ||
| assert.equal(metaTag?.getAttribute('content'), 'value'); | ||
|
|
||
| // Test 3: Verify title is in head | ||
| const titleTag = document.head.querySelector('title'); | ||
| assert.ok(titleTag, 'Title should be in head'); | ||
| assert.equal(titleTag?.textContent, 'CSR Test'); | ||
|
|
||
| // Test 4: Verify body elements are NOT in head | ||
| const pInHead = document.head.querySelector('p'); | ||
| assert.equal(pInHead, null, 'Paragraph element should NOT be in head'); | ||
| } | ||
| }); |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/runtime-browser/samples/head-nested-body-separation/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,10 @@ | ||
| <script> | ||
| import Child from './Child.svelte'; | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
| <title>CSR Test</title> | ||
| <Child /> | ||
| </svelte:head> | ||
|
|
||
| <main>Main content</main> |
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/server-side-rendering/samples/head-nested-body-separation/Child.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,5 @@ | ||
| <svelte:head> | ||
| <meta name="child-meta" content="test" /> | ||
| </svelte:head> | ||
|
|
||
| <div>Child body</div> |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/server-side-rendering/samples/head-nested-body-separation/_config.js
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 @@ | ||
| import { test } from '../../test'; | ||
|
|
||
| export default test({ | ||
| mode: ['async', 'sync'] | ||
| }); |
1 change: 1 addition & 0 deletions
1
...ges/svelte/tests/server-side-rendering/samples/head-nested-body-separation/_expected.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 @@ | ||
| <!--[--><main>Main content</main><!--]--> |
1 change: 1 addition & 0 deletions
1
...velte/tests/server-side-rendering/samples/head-nested-body-separation/_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 @@ | ||
| <!--22lmcx--><!--5uyrne--><meta name="child-meta" content="test"/><!----><div>Child body</div><!----><title>Parent Title</title> |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/server-side-rendering/samples/head-nested-body-separation/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,10 @@ | ||
| <script> | ||
| import Child from './Child.svelte'; | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
| <title>Parent Title</title> | ||
| <Child /> | ||
| </svelte:head> | ||
|
|
||
| <main>Main content</main> |
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.
I very doubt this logic makes sense. Aside from "Why do you mix head and body elements?", these elements became un-cleanable in case the component/head is wrapped in
#ifor something else dynamic. And probably breaks other blocks like#each.