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
pull/12210/head
Dominic Gannaway 5 days ago committed by GitHub
parent d9e8acd0d8
commit d3111db1ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure element dir properties persist with text changes

@ -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);

Loading…
Cancel
Save