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

WIP fix for #4731: preserveWhitespace in SSR #4737

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion src/compiler/compile/render_ssr/handlers/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
slot_scopes: Map<any, any>;
}) {

const children = remove_whitespace_children(node.children, node.next);
const children = (
options.preserveWhitespace
? node.children
: remove_whitespace_children(node.children, node.next)
);

// awkward special case
let node_contents;
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/compile/render_ssr/handlers/InlineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend

const slot_fns = [];

const children = remove_whitespace_children(node.children, node.next);
const children = (
options.preserveWhitespace
? node.children
: remove_whitespace_children(node.children, node.next)
);

if (children.length) {
const slot_scopes = new Map();
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/compile/render_ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export default function ssr(

const { name } = component;

const children = (
options.preserveWhitespace
? component.fragment.children
: trim(component.fragment.children)
);

// create $$render function
renderer.render(trim(component.fragment.children), Object.assign({
renderer.render(children, Object.assign({
locate: component.locate
}, options));

Expand Down
6 changes: 5 additions & 1 deletion test/server-side-rendering/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ describe("ssr", () => {
if (css.code) fs.writeFileSync(`${dir}/_actual.css`, css.code);

try {
assert.htmlEqual(html, expectedHtml);
if (compileOptions.preserveWhitespace) {
assert.equal(html, expectedHtml);
} else {
assert.htmlEqual(html, expectedHtml);
}
} catch (error) {
if (shouldUpdateExpected()) {
fs.writeFileSync(`${dir}/_expected.html`, html);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
compileOptions: {
preserveWhitespace: true
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

<div>
<div>
<p> Some text </p>
</div>
<select>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>

12 changes: 12 additions & 0 deletions test/server-side-rendering/samples/preserve-whitespace/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<div>
<div>
<p> Some text </p>
</div>
<select>
{#each [1, 2] as value}
<option>{value}</option>
{/each}
</select>
</div>