From 84d073ada55928a780118fbd80baeed9446c9806 Mon Sep 17 00:00:00 2001 From: tanhauhau Date: Sun, 27 Jun 2021 15:53:32 +0800 Subject: [PATCH] fix input value 0 for ssr --- src/compiler/compile/render_ssr/handlers/Element.ts | 4 +++- .../samples/apply-directives-in-order/_config.js | 2 +- test/runtime/samples/binding-circular/_config.js | 6 ------ .../binding-select-implicit-option-value/_config.js | 10 ---------- .../samples/binding-select-in-each-block/_config.js | 13 ------------- .../samples/binding-select-initial-value/_config.js | 12 ------------ .../samples/binding-select-late-2/_config.js | 5 ----- .../samples/binding-select-multiple/_config.js | 10 ---------- test/runtime/samples/binding-select/_config.js | 12 ------------ .../samples/bindings-global-dependency/_config.js | 3 ++- .../samples/component-binding-computed/_config.js | 4 ++++ .../samples/component-binding-store/_config.js | 5 +++++ .../samples/component-slot-fallback-6/_config.js | 4 ++++ .../samples/component-slot-spread-props/_config.js | 6 ++++++ .../_config.js | 2 +- .../store-invalidation-while-update-1/_config.js | 6 ++++++ .../store-invalidation-while-update-2/_config.js | 6 ++++++ .../samples/bindings-empty-string/_expected.html | 1 + .../samples/bindings-empty-string/main.svelte | 5 +++++ .../samples/bindings-zero/_expected.html | 2 ++ .../samples/bindings-zero/main.svelte | 6 ++++++ 21 files changed, 52 insertions(+), 72 deletions(-) create mode 100644 test/server-side-rendering/samples/bindings-empty-string/_expected.html create mode 100644 test/server-side-rendering/samples/bindings-empty-string/main.svelte create mode 100644 test/server-side-rendering/samples/bindings-zero/_expected.html create mode 100644 test/server-side-rendering/samples/bindings-zero/main.svelte diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index 03838039ad10..4357f963552f 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -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 +

`, diff --git a/test/runtime/samples/binding-circular/_config.js b/test/runtime/samples/binding-circular/_config.js index 505ed22beb2b..3e58ab2f98af 100644 --- a/test/runtime/samples/binding-circular/_config.js +++ b/test/runtime/samples/binding-circular/_config.js @@ -3,11 +3,5 @@ export default { - `, - - ssrHtml: ` - ` }; diff --git a/test/runtime/samples/binding-select-implicit-option-value/_config.js b/test/runtime/samples/binding-select-implicit-option-value/_config.js index cce1172f6a4f..1266602a476c 100644 --- a/test/runtime/samples/binding-select-implicit-option-value/_config.js +++ b/test/runtime/samples/binding-select-implicit-option-value/_config.js @@ -14,16 +14,6 @@ export default {

foo: 2

`, - ssrHtml: ` - - -

foo: 2

- `, - async test({ assert, component, target, window }) { const select = target.querySelector('select'); const options = [...target.querySelectorAll('option')]; diff --git a/test/runtime/samples/binding-select-in-each-block/_config.js b/test/runtime/samples/binding-select-in-each-block/_config.js index 89f40f8d485b..80ea375b7832 100644 --- a/test/runtime/samples/binding-select-in-each-block/_config.js +++ b/test/runtime/samples/binding-select-in-each-block/_config.js @@ -1,17 +1,4 @@ export default { - - ssrHtml: ` - - - - `, - html: ` - - - - - -

selected: b

- `, - props: { selected: 'b' }, diff --git a/test/runtime/samples/binding-select-late-2/_config.js b/test/runtime/samples/binding-select-late-2/_config.js index 42c45d13668b..f4b0088fb9e1 100644 --- a/test/runtime/samples/binding-select-late-2/_config.js +++ b/test/runtime/samples/binding-select-late-2/_config.js @@ -9,11 +9,6 @@ export default {

selected: two

`, - ssrHtml: ` - -

selected: two

- `, - test({ assert, component, target }) { component.items = [ 'one', 'two', 'three' ]; diff --git a/test/runtime/samples/binding-select-multiple/_config.js b/test/runtime/samples/binding-select-multiple/_config.js index b7d6c3589f2b..70a5620d05e3 100644 --- a/test/runtime/samples/binding-select-multiple/_config.js +++ b/test/runtime/samples/binding-select-multiple/_config.js @@ -4,16 +4,6 @@ export default { selected: [ 'two', 'three' ] }, - ssrHtml: ` - - -

selected: two, three

- `, - html: ` - - - - - -

selected: one

- `, - props: { selected: 'one' }, diff --git a/test/runtime/samples/bindings-global-dependency/_config.js b/test/runtime/samples/bindings-global-dependency/_config.js index 1180424e81db..907aa52e6e69 100644 --- a/test/runtime/samples/bindings-global-dependency/_config.js +++ b/test/runtime/samples/bindings-global-dependency/_config.js @@ -1,3 +1,4 @@ export default { - html: '' + html: '', + ssrHtml: '' }; diff --git a/test/runtime/samples/component-binding-computed/_config.js b/test/runtime/samples/component-binding-computed/_config.js index b2870140659c..f43a6834a883 100644 --- a/test/runtime/samples/component-binding-computed/_config.js +++ b/test/runtime/samples/component-binding-computed/_config.js @@ -3,6 +3,10 @@ export default { `, + ssrHtml: ` + + + `, async test({ assert, component, target, window }) { const input = new window.Event('input'); diff --git a/test/runtime/samples/component-binding-store/_config.js b/test/runtime/samples/component-binding-store/_config.js index d17b9e2d8098..8bbdab17ee50 100644 --- a/test/runtime/samples/component-binding-store/_config.js +++ b/test/runtime/samples/component-binding-store/_config.js @@ -4,6 +4,11 @@ export default {
`, + ssrHtml: ` + + +
+ `, async test({ assert, component, target, window }) { let count = 0; diff --git a/test/runtime/samples/component-slot-fallback-6/_config.js b/test/runtime/samples/component-slot-fallback-6/_config.js index b32d96db2e81..be47d31d0338 100644 --- a/test/runtime/samples/component-slot-fallback-6/_config.js +++ b/test/runtime/samples/component-slot-fallback-6/_config.js @@ -4,6 +4,10 @@ export default { {"value":""} `, + ssrHtml: ` + + {"value":""} + `, async test({ assert, target, window }) { const input = target.querySelector('input'); diff --git a/test/runtime/samples/component-slot-spread-props/_config.js b/test/runtime/samples/component-slot-spread-props/_config.js index 042bdca6ecec..7beda8d3d5a7 100644 --- a/test/runtime/samples/component-slot-spread-props/_config.js +++ b/test/runtime/samples/component-slot-spread-props/_config.js @@ -5,6 +5,12 @@ export default {
`, + ssrHtml: ` +
+ +
+
+ `, async test({ assert, component, target }) { component.value = 'foo'; diff --git a/test/runtime/samples/each-block-destructured-default-binding/_config.js b/test/runtime/samples/each-block-destructured-default-binding/_config.js index 3697e374412d..2ba27bff0361 100644 --- a/test/runtime/samples/each-block-destructured-default-binding/_config.js +++ b/test/runtime/samples/each-block-destructured-default-binding/_config.js @@ -4,7 +4,7 @@ export default { `, ssrHtml: ` - + `, diff --git a/test/runtime/samples/store-invalidation-while-update-1/_config.js b/test/runtime/samples/store-invalidation-while-update-1/_config.js index 6a931afeaf13..0f8ff1809b06 100644 --- a/test/runtime/samples/store-invalidation-while-update-1/_config.js +++ b/test/runtime/samples/store-invalidation-while-update-1/_config.js @@ -5,6 +5,12 @@ export default {
simple
`, + ssrHtml: ` + +
+
simple
+ + `, async test({ assert, component, target, window }) { const input = target.querySelector('input'); diff --git a/test/runtime/samples/store-invalidation-while-update-2/_config.js b/test/runtime/samples/store-invalidation-while-update-2/_config.js index 6c2538e564b4..2465b7d44495 100644 --- a/test/runtime/samples/store-invalidation-while-update-2/_config.js +++ b/test/runtime/samples/store-invalidation-while-update-2/_config.js @@ -5,6 +5,12 @@ export default { `, + ssrHtml: ` +
+
simple
+ + + `, async test({ assert, component, target, window }) { const input = target.querySelector('input'); diff --git a/test/server-side-rendering/samples/bindings-empty-string/_expected.html b/test/server-side-rendering/samples/bindings-empty-string/_expected.html new file mode 100644 index 000000000000..8344e198fad1 --- /dev/null +++ b/test/server-side-rendering/samples/bindings-empty-string/_expected.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/server-side-rendering/samples/bindings-empty-string/main.svelte b/test/server-side-rendering/samples/bindings-empty-string/main.svelte new file mode 100644 index 000000000000..7257d0f85e55 --- /dev/null +++ b/test/server-side-rendering/samples/bindings-empty-string/main.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/test/server-side-rendering/samples/bindings-zero/_expected.html b/test/server-side-rendering/samples/bindings-zero/_expected.html new file mode 100644 index 000000000000..d634c4b80f37 --- /dev/null +++ b/test/server-side-rendering/samples/bindings-zero/_expected.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/server-side-rendering/samples/bindings-zero/main.svelte b/test/server-side-rendering/samples/bindings-zero/main.svelte new file mode 100644 index 000000000000..5689bb8d9c48 --- /dev/null +++ b/test/server-side-rendering/samples/bindings-zero/main.svelte @@ -0,0 +1,6 @@ + + + + \ No newline at end of file