Skip to content

Fix update code being generated for module variable dependencies #5943

Closed
@j-delaney

Description

@j-delaney

As discussed in #5926 (comment), I'm already working on this and should hopefully have a PR up soon.

Svelte generates update code when a class: expression is dependent on a module variable but this shouldn't happen. The docs say:

Variables defined in module scripts are not reactive — reassigning them will not trigger a rerender even though the variable itself will update.

Test Case

https://svelte.dev/repl/ca93007e0e03454fbeda66bd6e2a6b9b?version=3.32.1
If you click the button, you'll see that o is not reactive (because it's a module var). But if you look at the JS output you'll see the component's update code isn't a noop like it should be, instead it's:

p(ctx, [dirty]) {
  if (dirty & /*o*/ 0) set_data(t0, o);
  
  if (dirty & /*o*/ 0) {
    toggle_class(div, "test", o);
  }
},

Cause

I'm pretty sure that this is because is_dynamic returns true for the module var. I'm looking into whether changing that behavior will break anything though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions