Skip to content

Commit 57aeddc

Browse files
pngwnConduitry
authored andcommitted
Prevent element property set from throwing errors for readonly properties. Fixes #3681.
1 parent 43245a3 commit 57aeddc

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634))
99
* Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660))
1010
* Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667))
11+
* Fix error resulting from trying to set a read-only property when spreading element attributes ([#3681](https://github.com/sveltejs/svelte/issues/3681))
1112

1213
## 3.12.1
1314

src/runtime/internal/dom.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ export function attr(node: Element, attribute: string, value?: string) {
9090
}
9191

9292
export function set_attributes(node: Element & ElementCSSInlineStyle, attributes: { [x: string]: string }) {
93+
// @ts-ignore
94+
const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
9395
for (const key in attributes) {
9496
if (key === 'style') {
9597
node.style.cssText = attributes[key];
96-
} else if (key in node) {
98+
} else if (descriptors[key] && descriptors[key].set) {
9799
node[key] = attributes[key];
98100
} else {
99101
attr(node, key, attributes[key]);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
skip_if_ssr: true, // DOM and SSR output is different, a separate SSR test exists
3+
html: `<input form="qux" list="quu" />`,
4+
5+
test({ assert, target }) {
6+
const div = target.querySelector('input');
7+
assert.equal(div.value, 'bar');
8+
}
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let props = {
3+
value: 'bar',
4+
form: 'qux',
5+
list: 'quu',
6+
};
7+
</script>
8+
9+
<input {...props} />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input value="bar" form="qux" list="quu" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let props = {
3+
value: 'bar',
4+
form: 'qux',
5+
list: 'quu',
6+
};
7+
</script>
8+
9+
<input {...props} />

0 commit comments

Comments
 (0)