-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly set
value
property of custom elements
Avoid going through the `element.value = element.__value = newValue` condition because `__value` is actually how Lit stores the current value on the element, and messing with that would break things: Lit would think the value hasn't changed (because `__value` is already set to the new value by us) and doesn't fire an update. fixes #15194
- Loading branch information
1 parent
f67cf20
commit 95fe4f2
Showing
4 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: properly set `value` property of custom elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
packages/svelte/tests/runtime-runes/samples/custom-element-attributes/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client', 'server'], | ||
mode: ['client'], | ||
async test({ assert, target }) { | ||
const my_element = /** @type HTMLElement & { object: { test: true }; } */ ( | ||
target.querySelector('my-element') | ||
); | ||
const my_link = /** @type HTMLAnchorElement & { object: { test: true }; } */ ( | ||
target.querySelector('a') | ||
); | ||
assert.equal(my_element.getAttribute('string'), 'test'); | ||
assert.equal(my_element.hasAttribute('object'), false); | ||
assert.deepEqual(my_element.object, { test: true }); | ||
|
||
const my_link = /** @type HTMLAnchorElement & { object: { test: true }; } */ ( | ||
target.querySelector('a') | ||
); | ||
assert.equal(my_link.getAttribute('string'), 'test'); | ||
assert.equal(my_link.hasAttribute('object'), false); | ||
assert.deepEqual(my_link.object, { test: true }); | ||
|
||
const [value1, value2] = target.querySelectorAll('value-element'); | ||
assert.equal(value1.shadowRoot?.innerHTML, '<span>test</span>'); | ||
assert.equal(value2.shadowRoot?.innerHTML, '<span>test</span>'); | ||
} | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/custom-element-attributes/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
<script module> | ||
customElements.define('value-element', class extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
set value(v) { | ||
if (this.__value !== v) { | ||
this.__value = v; | ||
this.shadowRoot.innerHTML = `<span>${v}</span>`; | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<my-element string="test" object={{ test: true }}></my-element> | ||
<a is="my-link" string="test" object={{ test: true }}></a> | ||
|
||
<value-element value="test"></value-element> | ||
<value-element {...{value: "test"}}></value-element> |