Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{some const} is declared in a module script and will not be reactive #6606

Closed
OJFord opened this issue Aug 1, 2021 · 0 comments · Fixed by #6607
Closed

{some const} is declared in a module script and will not be reactive #6606

OJFord opened this issue Aug 1, 2021 · 0 comments · Fixed by #6607

Comments

@OJFord
Copy link
Contributor

OJFord commented Aug 1, 2021

Describe the bug

#5847 added a warning when module variables are used reactively in non-module script.

This warning is triggered even if the variable is const. (And used reactively together with non-const variables, presumably!)

Reproduction

<script context="module">
export const doFoos = (a, b, c) => [a, b, c];
export const foo = 123;
</script>

<script>
export let bar;

$: foobar = doFoos(foo, bar, null);
</script>

Logs

(!) Plugin svelte: "doFoos" is declared in a module script and will not be reactive
(!) Plugin svelte: "foo" is declared in a module script and will not be reactive

System Info

System:
    OS: Linux 5.13 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 4.66 GB / 15.56 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.6.0 - /usr/bin/node
    Yarn: 1.22.11 - /usr/bin/yarn
    npm: 7.20.3 - /usr/bin/npm
  Browsers:
    Firefox: 90.0.2

Severity

annoyance

OJFord added a commit to OJFord/svelte that referenced this issue Aug 1, 2021
OJFord added a commit to OJFord/svelte that referenced this issue Aug 1, 2021
This generated a warning:

    <script context="module">
      export const foo = 123;
    </script>

    <script>
      $: console.log(foo);
    </script>

while this did not:

    <script>
      const foo = 123;
      $: console.log(foo);
    </script>

We don't need a warning to tell us that we will not be reactive to a
variable that isn't going to change anyway; regardless of whether or not
it's in a module.

(Maybe there should be a 'no reactive variable used' warning, but this
also happens in cases where other mutable variables are used; such as a
shared const formatter function, formatting a prop.)
@OJFord OJFord changed the title [const] is declared in a module script and will not be reactive {some const} is declared in a module script and will not be reactive Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant