Skip to content

Svelte 5: Function calls in markup not being memoized when located in adjacent text nodes #11089

Closed
@aradalvand

Description

@aradalvand

Describe the bug

See this REPL.

A few months ago an important change was made to Svelte 5's reactivity system, which that every function call in the markup would be memoized and would yield separate render effects, so as to avoid needless re-triggering of the function, since the computation could potentially be expensive. This was 100% the right decision; and this behavior is still in effect today (no pun intended).

For example, in the REPL above, the JS output shows two render effects; now, if you remove the printFoo(...) and printBar(...) invocations, you'll see that the two render effects will be combined into one, as expected (see example).

However, if you bring back printFoo(...) and printBar(...), and then try removing the <br/> between the two text nodes, the render effects will now be combined into one as well, even though function invocations should yield separate render effects (see example).

This is likely because the compiler tries to optimize the output by combining adjacent text nodes into the same render effects, but the "function call => separate render effect" rule should take precedence over that optimization. I think this was subtly overlooked.

Reproduction

The REPL linked above -> then remove the <br/>.

Logs

No response

System Info

-

Severity

blocking an upgrade

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions