From d3111db1efabfac4590726662519d5979a99da49 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 27 Jun 2024 14:40:19 +0100 Subject: [PATCH] fix: ensure element dir properties persist with text changes (#12204) * fix: ensure element dir properties persist with text changes * fix: ensure element dir properties persist with text changes * simplify --- .changeset/mighty-shoes-nail.md | 5 +++++ .../phases/3-transform/client/visitors/template.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/mighty-shoes-nail.md diff --git a/.changeset/mighty-shoes-nail.md b/.changeset/mighty-shoes-nail.md new file mode 100644 index 000000000..0a758d5f6 --- /dev/null +++ b/.changeset/mighty-shoes-nail.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure element dir properties persist with text changes diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 6a426db0d..b28c73c4d 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -1955,6 +1955,7 @@ export const template_visitors = { let has_content_editable_binding = false; let img_might_be_lazy = false; let might_need_event_replaying = false; + let has_direction_attribute = false; if (is_custom_element) { // cloneNode is faster, but it does not instantiate the underlying class of the @@ -1970,6 +1971,9 @@ export const template_visitors = { if (node.name === 'img' && attribute.name === 'loading') { img_might_be_lazy = true; } + if (attribute.name === 'dir') { + has_direction_attribute = true; + } if ( (attribute.name === 'value' || attribute.name === 'checked') && !is_text_attribute(attribute) @@ -2170,6 +2174,14 @@ export const template_visitors = { { ...context, state } ); + if (has_direction_attribute) { + // This fixes an issue with Chromium where updates to text content within an element + // does not update the direction when set to auto. If we just re-assign the dir, this fixes it. + context.state.update.push( + b.stmt(b.assignment('=', b.member(node_id, b.id('dir')), b.member(node_id, b.id('dir')))) + ); + } + if (child_locations.length > 0) { // @ts-expect-error location.push(child_locations);