Skip to content

[custom-element] style: directive can be overridden by style property on update #15310

Closed
@adiguba

Description

@adiguba

Describe the bug

Just found that the style: directive can be overridden by the style property on client-side update.

For example with something like that : <custom-element {style} style:color="red">
The color should alway be "red", even if the style contains a color.

This is the case on SSR and on init, but not when the style property is updated.

This seems to come from the fact that the generated code have two distincts template_effect() :

	$.template_effect(() => $.set_custom_element_data(custom_element, 'style', $.get(style)));
	// ...
	$.template_effect(() => $.set_style(custom_element, 'color', 'red'));

for node element, they are on the same template_effect :

	$.template_effect(() => {
		$.set_attribute(div, 'style', $.get(style));
		$.set_style(div, 'color', 'red');
	});

Reproduction

Example : click on the "green" button and the text of the custom-element will be green.
He should stay red...

https://svelte.dev/playground/hello-world?version=5.20.1#H4sIAAAAAAAACm2Q0WqEMBBFfyUMBRXa9T0bhX3rPzR90DgtsmMSkrFbkfx7NS6ULX0KOdxzM5MVbDchSHhFIiduLtAgShxGxqGCZ_gYCSPItxV48XtuBxu_WxfvT_ELiXfWdxH_48ZZRstbDahowui51VYzIYvIC6FoxFPkjrEsjCMXZE8zFtVZW1X_5q3qZ2ZnhbOGRnNt1rJq2lzQ3L3PgGiL1OZT1Uf-cM0c2U0vSDhto4g1e-l4X2a70RBw0NA-RlX9eD_qspe3-Fu8M83DGD11ixQ9OXM97zDldbK3_QnjN4PkMGN6Tz-m2oNahQEAAA==

Note that this work correctly for HTML node :
https://svelte.dev/playground/hello-world?version=5.20.1#H4sIAAAAAAAACm2OwUrFMBBFfyUMQltQu49J4e38B-OiTUYJTpOSTJ8-Sv_dNH3gxtXA5Zw7d4MwzggSXpEoiu-YyIkWnWd0HTzChyfMIN824NtycEdQ8rt1WZbnfEXiI5vGjP_lNgbGwKUGVLbJLzyYYJiQReYbodDiIfPI2DY2UkxyohWb7sUE1f_xQU0rcwwiBkvefumt7fRQC_Td-0yIodmHelV_8qfr_FVsFd7Pp7Iq2kBCZ2Cwa-Y4PyHhXKaqvvBVLPMZfxgkpxX39_0XtyY8BjABAAA=

Logs

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions