Skip to content

(Svelte 4) subscribed store in markup won't use module instance #13061

@theetrain

Description

@theetrain

Describe the bug

In a component with <script context="module">, some markup, and without <script>; having a writable store be set by an exported function won't cause reactive updates in the markup.

Adding an empty <script></script> will include writable store in compiled output.

Reproduction

Toast component: https://svelte.dev/repl/6c0757bed5044018ba5560733e7b56bf?version=4.2.19

  1. Click on button labelled "Click me"
  2. Observe empty Toast message

Workaround:

  1. Add <script></script> to the markup
  2. Observe new prop in compiled output (there are more changes in compiled output as well):
/* Toast.svelte generated by Svelte v4.2.19 */
import {
  SvelteComponent,
  append,
  append_styles,
  attr,
  component_subscribe,
  detach,
  element,
  init,
  insert,
  noop,
  safe_not_equal,
+ set_data,
+ text as text_1,
  toggle_class
} from "svelte/internal";
  1. Click button to present a working Toast message

Note this works totally fine in Svelte 5, in both Runes and non-Runes modes. Demo.

Logs

No response

System Info

Svelte 4.2.19

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    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