mirror of https://github.com/sveltejs/svelte
* fix: move Svelte runtime properties to symbols Prevents DOM clobbering * shorten names --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/18220/head
parent
a16ebc67bb
commit
e1cbbd9644
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: move Svelte runtime properties to symbols
|
||||
@ -0,0 +1,23 @@
|
||||
import { assert_ok, test } from '../../assert';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, waitUntil, window }) {
|
||||
const form = target.querySelector('form');
|
||||
const button = target.querySelector('button');
|
||||
const [i1, i2, i3] = target.querySelectorAll('input');
|
||||
assert_ok(form);
|
||||
assert_ok(button);
|
||||
|
||||
assert.equal(form.id, 'initial-form');
|
||||
assert.equal(form.className, 'first');
|
||||
assert.equal(window.getComputedStyle(form).backgroundColor, 'rgb(255, 0, 0)');
|
||||
|
||||
button.click();
|
||||
await waitUntil(() => form.id === 'updated-form');
|
||||
|
||||
assert.equal(form.id, 'updated-form');
|
||||
assert.equal(form.className, 'second');
|
||||
assert.equal(i3.id, '', 'input clobbered form');
|
||||
assert.equal(window.getComputedStyle(form).backgroundColor, 'rgb(0, 0, 255)');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
<script>
|
||||
let form_attributes = $state({ id: 'initial-form' });
|
||||
let class_name = $state('first');
|
||||
let background_color = $state('rgb(255, 0, 0)');
|
||||
|
||||
function update() {
|
||||
form_attributes = { id: 'updated-form' };
|
||||
class_name = 'second';
|
||||
background_color = 'rgb(0, 0, 255)';
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={update}>update</button>
|
||||
|
||||
<form {...form_attributes} class={class_name} style:background-color={background_color}>
|
||||
<!-- the once non-symbol-ified hidden properties we used -->
|
||||
<input {...{ name: '__className' }} value="x" />
|
||||
<input {...{ name: '__style' }} value="y" />
|
||||
<input {...{ name: '__attributes' }} value="z" />
|
||||
</form>
|
||||
Loading…
Reference in new issue