Skip to content

Adding a comment changes the semantics of the code significantly, as well a related potential reactivity bug #9088

@Kcwidman

Description

@Kcwidman

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:

  1. some prop (so far I've only gotten it to work with a list) get's passed to a component
  2. a copy or a mapping of that component is made
  3. the copy is displayed in markup (I'm guessing if it's not, then the compiler doesn't deem it necessary to update it)
  4. 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:

  1. 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
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompilerChanges relating to the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions