Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adiguba opened this issue Feb 16, 2025 · 0 comments

Comments

@adiguba
Copy link
Contributor

adiguba commented Feb 16, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants