Skip to content

Commit

Permalink
[fix] Spread component props immutably during SSR (#8176)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EmilTholin authored Jan 10, 2023
1 parent aa98397 commit b06e435
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend
let props;

if (uses_spread) {
props = x`@_Object.assign(${
props = x`@_Object.assign({}, ${
node.attributes
.map(attribute => {
if (attribute.is_spread) {
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions test/runtime/samples/spread-component-immutable/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const obj = {
x: 1,
y: 2,
z: 3
};

export default {
props: {
obj
},

test({ assert }) {
assert.deepEqual(obj, { x: 1, y: 2, z: 3 });
}
};
7 changes: 7 additions & 0 deletions test/runtime/samples/spread-component-immutable/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import Widget from './Widget.svelte';
export let obj;
</script>

<Widget {...obj} x={2} />

0 comments on commit b06e435

Please sign in to comment.