Skip to content

SSR compiler does not unwrap $derived thunk for dynamic components with member expressions #18191

@envyvox

Description

@envyvox

Describe the bug

In SSR mode, when a dynamic component is rendered via a member expression (<a.b.c />) where a is a $derived, the compiler outputs a.b.c directly instead of a().b.c. Since server-side $derived returns a thunk (function) after #17674, a.b is undefined and accessing a.b.c throws TypeError: Cannot read properties of undefined (reading 'c').

The client compiler handles this correctly by emitting $.get(a).b.c.

Workaround

Capture each access in its own $derived:

<script>
  const platformIcons = $derived(icons);
  const Icon = $derived(platformIcons.currency.Icon);
</script>
<Icon />

That generates $.derived(() => platformIcons().currency.Icon), which works.

Reproduction

https://svelte.dev/playground/2fa2e050cfa44e94a3141dca53ce4ac2?version=latest

<script>
  let icons = $state({ currency: { Icon: () => 'x' } });
  const platformIcons = $derived(icons);
</script>

<platformIcons.currency.Icon />

Logs

System Info

System:
    OS: Linux 6.19 Fedora Linux 43 (KDE Plasma Desktop Edition)
    CPU: (12) x64 AMD Ryzen 5 7500F 6-Core Processor
    Memory: 14.92 GB / 31.05 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.14.0 - /home/envyvox/.local/share/pnpm/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.9.0 - /home/envyvox/.local/share/pnpm/npm
    pnpm: 10.32.1 - /home/envyvox/.local/share/pnpm/pnpm
  Browsers:
    Firefox: 149.0.2
    Firefox Developer Edition: 149.0.2
  npmPackages:
    svelte: 5.55.5 => 5.55.5

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions