Skip to content

Commit d3111db

Browse files
authored
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
1 parent d9e8acd commit d3111db

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.changeset/mighty-shoes-nail.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure element dir properties persist with text changes

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

+12
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,7 @@ export const template_visitors = {
19551955
let has_content_editable_binding = false;
19561956
let img_might_be_lazy = false;
19571957
let might_need_event_replaying = false;
1958+
let has_direction_attribute = false;
19581959

19591960
if (is_custom_element) {
19601961
// cloneNode is faster, but it does not instantiate the underlying class of the
@@ -1970,6 +1971,9 @@ export const template_visitors = {
19701971
if (node.name === 'img' && attribute.name === 'loading') {
19711972
img_might_be_lazy = true;
19721973
}
1974+
if (attribute.name === 'dir') {
1975+
has_direction_attribute = true;
1976+
}
19731977
if (
19741978
(attribute.name === 'value' || attribute.name === 'checked') &&
19751979
!is_text_attribute(attribute)
@@ -2170,6 +2174,14 @@ export const template_visitors = {
21702174
{ ...context, state }
21712175
);
21722176

2177+
if (has_direction_attribute) {
2178+
// This fixes an issue with Chromium where updates to text content within an element
2179+
// does not update the direction when set to auto. If we just re-assign the dir, this fixes it.
2180+
context.state.update.push(
2181+
b.stmt(b.assignment('=', b.member(node_id, b.id('dir')), b.member(node_id, b.id('dir'))))
2182+
);
2183+
}
2184+
21732185
if (child_locations.length > 0) {
21742186
// @ts-expect-error
21752187
location.push(child_locations);

0 commit comments

Comments
 (0)