-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
Describe the bug
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.
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();Reproduction
Logs
No response
System Info
nextSeverity
blocking an upgrade
gterras
Metadata
Metadata
Assignees
Labels
No labels