diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index b57d24ae9c..7a0bdbaa06 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -872,12 +872,12 @@ export default class ElementWrapper extends Wrapper { ? x`@set_dynamic_element_data(${this.node.tag_expr.manipulate(block)})` : x`@set_attributes`; - block.chunks.hydrate.unshift( + block.chunks.hydrate.push( b`${fn}(${this.var}, ${this.element_data_name});` ); if (this.has_dynamic_attribute) { - block.chunks.update.unshift(b` + block.chunks.update.push(b` ${fn}(${this.var}, ${this.element_data_name} = @get_spread_update(${levels}, [ ${updates} ])); diff --git a/test/runtime/samples/component-event-handler-contenteditable4/_config.js b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/_config.js similarity index 84% rename from test/runtime/samples/component-event-handler-contenteditable4/_config.js rename to test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/_config.js index bc9d65d1c3..3763360fd8 100644 --- a/test/runtime/samples/component-event-handler-contenteditable4/_config.js +++ b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/_config.js @@ -1,3 +1,4 @@ +// A puppeteer test because JSDOM doesn't support contenteditable export default { html: '
', diff --git a/test/runtime/samples/component-event-handler-contenteditable4/main.svelte b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/main.svelte similarity index 100% rename from test/runtime/samples/component-event-handler-contenteditable4/main.svelte rename to test/runtime-puppeteer/samples/component-event-handler-contenteditable-false/main.svelte diff --git a/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/_config.js b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/_config.js new file mode 100644 index 0000000000..de65bd6627 --- /dev/null +++ b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/_config.js @@ -0,0 +1,24 @@ +// A puppeteer test because JSDOM doesn't support contenteditable +export default { + html: '', + ssrHtml: '', + + 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'); + } +}; diff --git a/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/main.svelte b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/main.svelte new file mode 100644 index 0000000000..ed301e8d20 --- /dev/null +++ b/test/runtime-puppeteer/samples/component-event-handler-contenteditable-spread/main.svelte @@ -0,0 +1,11 @@ + + +