Skip to content

Commit

Permalink
fix input value 0 for ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jun 29, 2021
1 parent 000c7ca commit b02e01c
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/compiler/compile/render_ssr/handlers/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
} else if (binding.name === 'value' && node.name === 'textarea') {
const snippet = expression.node;
node_contents = x`${snippet} || ""`;
} else if (binding.name === 'value' && node.name === 'select') {
// NOTE: do not add "value" attribute on <select />
} else {
const snippet = expression.node;
renderer.add_expression(x`@add_attribute("${name}", ${snippet}, 1)`);
renderer.add_expression(x`@add_attribute("${name}", ${snippet}, ${boolean_attributes.has(name) ? 1 : 0})`);
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/runtime/samples/apply-directives-in-order/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
`,

ssrHtml: `
<input>
<input value="">
<p></p>
`,

Expand Down
3 changes: 2 additions & 1 deletion test/runtime/samples/bindings-global-dependency/_config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
html: '<input type="text">'
html: '<input type="text">',
ssrHtml: '<input type="text" value="">'
};
4 changes: 4 additions & 0 deletions test/runtime/samples/component-binding-computed/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export default {
<label>firstname <input></label>
<label>lastname <input></label>
`,
ssrHtml: `
<label>firstname <input value=""></label>
<label>lastname <input value=""></label>
`,

async test({ assert, component, target, window }) {
const input = new window.Event('input');
Expand Down
5 changes: 5 additions & 0 deletions test/runtime/samples/component-binding-store/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export default {
<input />
<div></div>
`,
ssrHtml: `
<input value=""/>
<input value=""/>
<div></div>
`,

async test({ assert, component, target, window }) {
let count = 0;
Expand Down
4 changes: 4 additions & 0 deletions test/runtime/samples/component-slot-fallback-6/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default {
<input>
{"value":""}
`,
ssrHtml: `
<input value="">
{"value":""}
`,

async test({ assert, target, window }) {
const input = target.querySelector('input');
Expand Down
6 changes: 6 additions & 0 deletions test/runtime/samples/component-slot-spread-props/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
<div class="foo"></div>
</div>
`,
ssrHtml: `
<div>
<input value="" />
<div class="foo"></div>
</div>
`,

async test({ assert, component, target }) {
component.value = 'foo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
<input />
`,
ssrHtml: `
<input />
<input value="" />
<input value="hello" />
`,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
<div>simple</div>
<button>click me</button>
`,
ssrHtml: `
<input value="">
<div></div>
<div>simple</div>
<button>click me</button>
`,

async test({ assert, component, target, window }) {
const input = target.querySelector('input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
<input>
<button>click me</button>
`,
ssrHtml: `
<div></div>
<div>simple</div>
<input value="">
<button>click me</button>
`,

async test({ assert, component, target, window }) {
const input = target.querySelector('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input value=''>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let foo = '';
</script>

<input bind:value={foo} >
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<input value="0" type="number">
<input value="0" type="range">
6 changes: 6 additions & 0 deletions test/server-side-rendering/samples/bindings-zero/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
export let foo = 0;
</script>

<input type="number" bind:value={foo} >
<input type="range" bind:value={foo} >

0 comments on commit b02e01c

Please sign in to comment.