We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Code like this...
<script> import Child from './Child.svelte'; </script> <Child random={Math.random().toFixed(2)} />
...generates code like this:
var fragment = $.comment($$anchor); var node = $.child_frag(fragment); Child(node, { get random() { return Math.random().toFixed(2); } }); $.close_frag($$anchor, fragment); $.pop();
This means that each random reference within Child will be different. It also means that we're computing stuff unnecessarily.
random
Child
To solve this, we probably need to use a derived source...
var fragment = $.comment($$anchor); var node = $.child_frag(fragment); { const random = $.derived(() => Math.random().toFixed(2)); Child(node, { get random() { return $.get(random); } }); } $.close_frag($$anchor, fragment); $.pop();
...though in some cases (including this one) we could presumably detect via static analysis that no signals are used, and that we can do this instead:
var fragment = $.comment($$anchor); var node = $.child_frag(fragment); Child(node, { random: Math.random().toFixed(2) }); $.close_frag($$anchor, fragment); $.pop();
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE42OywqDMBBFfyWEggoSoUurQil01y-oXYiJGDDJkIylJeTf66O0Cxft8lzmzj2ednIQjuZXT3WjBM3pEYCmFJ8wg7uLAcXEzoy2nZPCtVYCVrWuUSowFsmplwMnnTWKRCxbiK3F6FDrIvs2dLHe2kZzo0p_abBnK8QJQ3OWD8HjfRJIVk2jynDZScFpjnYUIf04Ll_-tRwEEv-eJIGUZAfWgIuTjRxUfj0LRQbV72CreAsvyJ0MP1IBAAA=
No response
next
blocking an upgrade
The text was updated successfully, but these errors were encountered:
fix: ensure computed props are cached with derived (#9757)
2017af4
Fixes #9751
trueadm
Successfully merging a pull request may close this issue.
Describe the bug
Code like this...
...generates code like this:
This means that each
random
reference withinChild
will be different. It also means that we're computing stuff unnecessarily.To solve this, we probably need to use a derived source...
...though in some cases (including this one) we could presumably detect via static analysis that no signals are used, and that we can do this instead:
Reproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE42OywqDMBBFfyWEggoSoUurQil01y-oXYiJGDDJkIylJeTf66O0Cxft8lzmzj2ednIQjuZXT3WjBM3pEYCmFJ8wg7uLAcXEzoy2nZPCtVYCVrWuUSowFsmplwMnnTWKRCxbiK3F6FDrIvs2dLHe2kZzo0p_abBnK8QJQ3OWD8HjfRJIVk2jynDZScFpjnYUIf04Ll_-tRwEEv-eJIGUZAfWgIuTjRxUfj0LRQbV72CreAsvyJ0MP1IBAAA=
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: