-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- split logic up into "is this a contenteditable element" and depending on the outcome use either .wholeText or .data to check if an update is necessary - add to puppeteer because jsdom does not support contenteditable - one test is skipped it because it fails right now but helps test #5018 --------- Co-authored-by: suxin2017 <[email protected]> Co-authored-by: Simon H <[email protected]> Co-authored-by: Simon Holthausen <[email protected]>
- Loading branch information
1 parent
6ce6f14
commit a2170f5
Showing
16 changed files
with
197 additions
and
41 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
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
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
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
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
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
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: 13 additions & 0 deletions
13
test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/_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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// A puppeteer test because JSDOM doesn't support contenteditable | ||
export default { | ||
html: '<div contenteditable="false"></div>', | ||
|
||
async test({ assert, target, component, window }) { | ||
const div = target.querySelector('div'); | ||
const text = window.document.createTextNode('a'); | ||
div.insertBefore(text, null); | ||
assert.equal(div.textContent, 'a'); | ||
component.text = 'bcde'; | ||
assert.equal(div.textContent, 'bcdea'); | ||
} | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script> | ||
export let text = ''; | ||
const updater = (event) => {text = event.target.textContent} | ||
</script> | ||
|
||
<div contenteditable="false" on:input={updater}>{text}</div> |
24 changes: 24 additions & 0 deletions
24
test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/_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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// A puppeteer test because JSDOM doesn't support contenteditable | ||
export default { | ||
html: '<div contenteditable="true"></div>', | ||
ssrHtml: '<div contenteditable=""></div>', | ||
|
||
async test({ assert, target, window }) { | ||
// this tests that by going from contenteditable=true to false, the | ||
// content is correctly updated before that. This relies on the order | ||
// of the updates: first updating the content, then setting contenteditable | ||
// to false, which means that `set_data_maybe_contenteditable` is used and not `set_data`. | ||
// If the order is reversed, https://github.com/sveltejs/svelte/issues/5018 | ||
// would be happening. The caveat is that if we go from contenteditable=false to true | ||
// then we will have the same issue. To fix this reliably we probably need to | ||
// overhaul the way we handle text updates in general. | ||
// If due to some refactoring this test fails, it's probably fine to ignore it since | ||
// this is a very specific edge case and the behavior is unstable anyway. | ||
const div = target.querySelector('div'); | ||
const text = window.document.createTextNode('a'); | ||
div.insertBefore(text, null); | ||
const event = new window.InputEvent('input'); | ||
await div.dispatchEvent(event); | ||
assert.equal(div.textContent, 'a'); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let text = ""; | ||
const updater = (event) => { | ||
text = event.target.textContent; | ||
}; | ||
$: spread = { | ||
contenteditable: text !== "a", | ||
}; | ||
</script> | ||
|
||
<div {...spread} on:input={updater}>{text}</div> |
33 changes: 33 additions & 0 deletions
33
test/runtime-puppeteer/samples/component-event-handler-contenteditable/_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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// A puppeteer test because JSDOM doesn't support contenteditable | ||
export default { | ||
html: '<div contenteditable=""></div>', | ||
|
||
// Failing test for https://github.com/sveltejs/svelte/issues/5018, fix pending | ||
// It's hard to fix this because in order to do that, we would need to change the | ||
// way the value is compared completely. Right now it compares the value of the | ||
// first text node, but it should compare the value of the whole content | ||
skip: true, | ||
|
||
async test({ assert, target, window }) { | ||
const div = target.querySelector('div'); | ||
|
||
let text = window.document.createTextNode('a'); | ||
div.insertBefore(text, null); | ||
let event = new window.InputEvent('input'); | ||
await div.dispatchEvent(event); | ||
assert.equal(div.textContent, 'a'); | ||
|
||
// When a user types a newline, the browser inserts a <div> element | ||
const inner_div = window.document.createElement('div'); | ||
div.insertBefore(inner_div, null); | ||
event = new window.InputEvent('input'); | ||
await div.dispatchEvent(event); | ||
assert.equal(div.textContent, 'a'); | ||
|
||
text = window.document.createTextNode('b'); | ||
inner_div.insertBefore(text, null); | ||
event = new window.InputEvent('input'); | ||
await div.dispatchEvent(event); | ||
assert.equal(div.textContent, 'ab'); | ||
} | ||
}; |
File renamed without changes.
15 changes: 0 additions & 15 deletions
15
test/runtime/samples/component-event-handler-contenteditable/_config.js
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
export default { | ||
html:'<div>same text</div>', | ||
async test({ assert, target }) { | ||
await new Promise(f => setTimeout(f, 10)); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div>same text text</div> | ||
`); | ||
} | ||
}; |
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,8 @@ | ||
<script> | ||
let text = 'same'; | ||
setTimeout(() => { | ||
text = 'same text'; | ||
}, 5); | ||
</script> | ||
|
||
<div>{text} text</div> |