Skip to content
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

fix: ssr comments in head elements that require raw content #10936

Merged
merged 8 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/khaki-tomatoes-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: ssr comments in head elements that require raw content
6 changes: 4 additions & 2 deletions packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const VoidElements = new Set([
'wbr'
]);

export const RawTextElements = new Set(['textarea', 'script', 'style', 'title']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you put these in constants.js where all the others are? Plus it doesn't need to be a Set, an array here would be slightly faster than a Set as there are so few elements in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have moved and changed it now. I had just used the same method as the VoidElements set that was above.


/**
* @type {Element | null}
*/
Expand Down Expand Up @@ -162,11 +164,11 @@ export function element(payload, tag, attributes_fn, children_fn) {
payload.out += `>`;

if (!VoidElements.has(tag)) {
if (tag !== 'textarea') {
if (!RawTextElements.has(tag)) {
payload.out += '<![>';
}
children_fn();
if (tag !== 'textarea') {
if (!RawTextElements.has(tag)) {
payload.out += '<!]>';
}
payload.out += `</${tag}>`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
compileOptions: {
preserveComments: true
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<![>
<![>
<title>lorem</title>
<!]>
<![>
<style>
.ipsum {
display: block;
}
</style>
<!]>
<![>
<script>
console.log(true);
</script>
<!]>
<!]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svelte:element this="title">lorem</svelte:element>
<svelte:element this="style">{'.ipsum { display: block; }'}</svelte:element>
<svelte:element this="script">{'console.log(true);'}</svelte:element>