sveltejs / svelte · Issue No. 18465
Function call in class: and style: directives are inconsistent with standard attributes.
color={func()} will be re-trigerred only if a reactive state is updated.style:color={func()} will also be re-trigerred when any of the other style: directive is updated
In this example we use an function to generate a random color, ans a state to change the size of the text (using the obsolete<font> only in order to have a visual result).
Updating the size of the text do no re-trigger the function :
https://svelte.dev/playground/hello-world?version=5.56.4#H4sIAAAAAAAACm2QQW_bMAyF_wrHDbC82U67dRngOQGGAcMuPfU476DYjCNApQyJTrsZ_u-D7BQLCuskfHwkH9-IrB8JS_xJ1jp4ct62oKg1Qm2KGR6NpYDlrxHlTx91EWD20vWt74twJiuRHXSgNd44FmIJWGIVGm962ddccy3HgRsxjqEjJq-FvjvrvEphjNVaGsdBoIkQdpC8TeADqHstp8Jrbt2jSuE93Dz_mF9aiHsQb7hTt9u06HX7INqLSm6SDLZpEaxpSOXb9Ov_4c5SYV2nanzloMZs2fui9iSD54XNaFpOsCQQzF-CHbwLooVUcpdcmrjaXJ0bVSVUgSw1AgfDbXnWdqDdGCtT1Ejl-pjH_rbaXH7X9OMq_bRK71bp51W6XaVfrmi1WWzPh1StOS_KN3kOQzDcgYbq6Fj2IA4CEciJoDlp7gjyfBHH-pLfbnyV9jRHeB1ELYFE4uTLfBFvDoNQmGdt5mXR1-IFMxR6FizFDzT9zlC0sU-GWyyP2gaa_gGZOj6-5wIAAA
In this exemple, we do the same thing using style: directive, and updating and changing the size restarts the generateColor() function :
https://svelte.dev/playground/hello-world?version=5.56.4#H4sIAAAAAAAACnWQQY_TMBCF_8poQIqzZNMWlh5CWgkhIS6c9kg4eONpseSOI3uS3SXKf0dOu6KsiA-W_L33bL8ZkfWJsMJv5JyHRx-cAUXGCpkcCzxYRxGrHyPKc5d8CWDxkvrcdWUcyEliDzrS_3jrWYglYoV1bIPtZN9ww40cem7FeoYjMQUt9MU7H1QOY1IbaT1HgTZB2EH2JoN3oL5r-VUGzcafVA43sH76Oq-8FH8vwfJRbbZ52WlzLzqIytZZAdu8jM62pG63-ae_l3tHpfNH1eCrHzRYnN99cQeSPvCZzWg6V3AkEO1vgh28jaKFVLahU3aJcb26Kpx8FdSRHLUCD5ZNNWjX025MypQ8UvsuTWS_Lj_SqV5dTtfKZokvJt4v8cXEhwV-9w-vV-cqc7na2AGiPDuq5iHtxlcjnS7qwbPcpsLXtRuJJGL5CH1M-2wFYwO1YgdKbxk77BvGAoWeBCsJPU0_CxRt3aNlg9VBu0jTH1Mj-xDRAgAA
It's event worse with async function, since this can lead to an await_reactivity_loss :
We can see that the same problem can occurs on the class: directives :
Note : I'm working on a fix for that
REPL
annoyance
Relay reads this issue against the repository's contribution signals: the files it is likely to touch, how the maintainers triage work this size, and what the first contribution would exercise.
The full analysis for this issue is still being assembled. Until then, the description above and the thread on GitHub are the most reliable context.