Skip to content

Commit b06e435

Browse files
authored
[fix] Spread component props immutably during SSR (#8176)
By passing an empty object literal as first argument to Object.assign we can avoid having objects spread as props on a component being mutated during SSR. Fixes #8171
1 parent aa98397 commit b06e435

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/compiler/compile/render_ssr/handlers/InlineComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend
3636
let props;
3737

3838
if (uses_spread) {
39-
props = x`@_Object.assign(${
39+
props = x`@_Object.assign({}, ${
4040
node.attributes
4141
.map(attribute => {
4242
if (attribute.is_spread) {

test/runtime/samples/spread-component-immutable/Widget.svelte

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const obj = {
2+
x: 1,
3+
y: 2,
4+
z: 3
5+
};
6+
7+
export default {
8+
props: {
9+
obj
10+
},
11+
12+
test({ assert }) {
13+
assert.deepEqual(obj, { x: 1, y: 2, z: 3 });
14+
}
15+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import Widget from './Widget.svelte';
3+
4+
export let obj;
5+
</script>
6+
7+
<Widget {...obj} x={2} />

0 commit comments

Comments
 (0)