Skip to content

Svelte 5: Context is undefined on the client side #11442

@HighFunctioningSociopathSH

Description

Describe the bug

Context isn't set properly and is undefined on the client side.

Reproduction

WrapperTest.svelte

<script lang="ts">
  import { setContext, type Snippet } from "svelte";

  let { children }: { children?: Snippet } = $props();

  let obj = {};

  setContext("test", obj);
</script>

{@render children?.()}

Test.svelte

<script lang="ts">
  import { getContext } from "svelte";

  const test = getContext("test");
  console.log(test); // test is undefined;
</script>

+page.svelte

<script lang="ts">
  import Test from "$components/Test/Test.svelte";
  import WrapperTest from "$components/Test/WrapperTest.svelte";
</script>

<WrapperTest>
  <Test></Test>
</WrapperTest>

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 7.00 GB / 15.63 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.3 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^5.0.0-next.121 => 5.0.0-next.121

Severity

blocking all usage of svelte

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