sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
76.8k stars 3.98k forks source link

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

Closed HighFunctioningSociopathSH closed 2 weeks ago

HighFunctioningSociopathSH commented 2 weeks ago

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

Hugos68 commented 2 weeks ago

The reproduction does not seem to reproduce the issue: REPL Can you confirm it works in the REPL?

mikiadev commented 2 weeks ago

As far as I can see this is a duplicate of #11429 fixed by #11438

Dudek-AMS commented 2 weeks ago

I have the same issue. setContext/getContext does not work inside snippets

Dudek-AMS commented 2 weeks ago

@mikiadev yeah looks good - so we'd just need to wait for new .next release

dummdidumm commented 2 weeks ago

Changesets fucked up somehow, so -next.122 never made it to npm - pushed another release, .123 should fix this