mirror of https://github.com/sveltejs/svelte
Merge 6c807a50cc into 44a7813730
commit
bfa239f10a
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: force the first run innerText/innerHTML/textContent written for content_editable_bind
|
||||
@ -0,0 +1,20 @@
|
||||
import { flushSync } from '../../../../src/index-client';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, target }) {
|
||||
const h1 = /** @type {HTMLDivElement} */ (target.querySelector('h1'));
|
||||
|
||||
assert.equal(h1.textContent, 'h');
|
||||
// don't use h1.textContent because h1.textContent will overwrite all childNodes
|
||||
// The childNode created by {myTextBlock.current} is the reason for duplication
|
||||
const textNode =
|
||||
[...h1.childNodes].findLast((n) => n.nodeType === Node.TEXT_NODE) ??
|
||||
h1.appendChild(document.createTextNode(''));
|
||||
textNode.nodeValue = 'he';
|
||||
h1.dispatchEvent(new window.Event('input'));
|
||||
flushSync();
|
||||
|
||||
assert.equal(h1.textContent, 'he');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
const myTextBlock = $state({
|
||||
current: 'h'
|
||||
})
|
||||
|
||||
const renderTag = $state("h1")
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:element this={renderTag} contenteditable="plaintext-only" class="test" bind:textContent={myTextBlock.current}>
|
||||
{myTextBlock.current}
|
||||
</svelte:element>
|
||||
@ -0,0 +1,19 @@
|
||||
import { flushSync } from '../../../../src/index-client';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, target }) {
|
||||
const h1 = /** @type {HTMLDivElement} */ (target.querySelector('h1'));
|
||||
assert.equal(h1.textContent, '');
|
||||
// don't use h1.textContent because h1.textContent will overwrite all childNodes
|
||||
// The childNode created by {myTextBlock.current} is the reason for duplication
|
||||
const textNode =
|
||||
[...h1.childNodes].findLast((n) => n.nodeType === Node.TEXT_NODE) ??
|
||||
h1.appendChild(document.createTextNode(''));
|
||||
textNode.nodeValue = 'h';
|
||||
h1.dispatchEvent(new window.Event('input'));
|
||||
flushSync();
|
||||
|
||||
assert.equal(h1.textContent, 'h');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
const myTextBlock = $state({
|
||||
current: ''
|
||||
})
|
||||
|
||||
const renderTag = $state("h1")
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:element this={renderTag} contenteditable="plaintext-only" class="test" bind:textContent={myTextBlock.current}>
|
||||
{myTextBlock.current}
|
||||
</svelte:element>
|
||||
Loading…
Reference in new issue