-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
Adding a comment changes the semantics of the code. In fact, adding a comment fixes another presumed reactivity bug.
Let's walk through the original presumed bug first, then I'll explain the bizarre comment behavior.
For the rest of this report, I'll be referring to this REPL which replicates the issue.
Note: I have also replicated this with a running svelte-kit application as well.
Replication:
- some prop (so far I've only gotten it to work with a list) get's passed to a component
- a copy or a mapping of that component is made
- the copy is displayed in markup (I'm guessing if it's not, then the compiler doesn't deem it necessary to update it)
- at some later point, a function manually triggers reactivity on the copy (in this case the clickAction handler)
Bug:
The original list will have reactivity triggered on it even though it's been copied by value. The expected behavior is that the original list should not have reactivity triggered on it all. This is validated in the JS output, showing that the clickAction handler invalidates both names and namesCopy.
Findings:
- this only happens if names is a prop, if you toggle the comments on the lines defining the names list in DataTable.svelte,
the behavior works as expected - adding a comment to the side of the line that manually triggers reactivity on the copy changes the behavior of the
code (this is also reflected in the JS output)
Reproduction
Replication is mentioned in tandem with bug description.
Logs
No response
System Info
System:
OS: Linux 4.18 CentOS Stream 8
CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
Memory: 44.25 GB / 62.44 GB
Container: Yes
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 18.16.0 - /usr/bin/node
npm: 9.5.1 - /usr/bin/npm
pnpm: 8.4.0 - /usr/bin/pnpm
Browsers:
Chrome: 114.0.5735.90
Severity
annoyance