Skip to content

Commit

Permalink
WIP fix for sveltejs#4731: preserveWhitespace in SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbroersma committed Apr 28, 2020
1 parent e3fef0f commit 33d8a65
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/compiler/compile/render_ssr/handlers/Element.ts
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
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
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
@@ -0,0 +1,5 @@
export default {
compileOptions: {
preserveWhitespace: true
}
};
@@ -0,0 +1,11 @@

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

11 changes: 11 additions & 0 deletions test/server-side-rendering/samples/preserve-whitespace/main.svelte
@@ -0,0 +1,11 @@

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

0 comments on commit 33d8a65

Please sign in to comment.