Error for libraries that use context API inside a store
JustinVoitel opened this issue · comments
Description
It seems like something is broken when using stores that rely on getContext() in some way. Currently in my project the goto helper of routify and mutate() function of @urql/svelte are getting both the same error:
Reproduction
npm svite create -t routify-mdsvex -ts
- add this to
src/store.ts
:
import { get, writable } from "svelte/store";
import { goto } from "@roxi/routify";
function createTestStore() {
const store = writable({});
return {
subscribe: store.subscribe,
gotoUrl: (url: string) => {
const gotoRoutify = get(goto);
gotoRoutify(url);
},
};
}
export const testStore = createTestStore();
- add this to
src/pages/index.svelte
:
<script lang="ts">
import { testStore } from "./../store";
function handleGoto() {
testStore.gotoUrl("/bla");
}
</script>
<h1>Welcome to the routify example</h1>
Check out the link in the nav
<button on:click={handleGoto}>goto</button>
- click button in dev
- clone same repo
- add dependency
npm i @urql/svelte
- add this to
src/App.svelte
:
<script lang="ts">
import { Router } from "@roxi/routify/runtime";
import { routes } from "../.routify/routes";
import { initClient } from "@urql/svelte";
initClient({ url: "/graphql" });
</script>
<Router {routes} />
- add this to
src/pages/index.ts
:
<script lang="ts">
import { mutate } from "@urql/svelte";
function handleClick() {
mutate(SOME_QUERY).then((e) => {
console.log(e);
});
}
</script>
<h1>Welcome to the routify example</h1>
Check out the link in the nav
<button on:click={handleClick}>mutation</button>
Additional Information
- operating system: windows 10 wsl2
- versions for
- node v14.8.0
- npm 6.14.7
- svite 0.7.1
- vite
- svelte 3.26.0
- logs with debug enabled
- start svite with
svite --debug
flag
- start svite with
will try to downgrade svite tomorrow till its working again and comment here
can confirm when using the latest ts template for routify-mdsvex (svite 0.7.1), downgrading svelte to version 3.24.1
will make my first reproduction example work again (and I guess my second one aswell)
As discussed on discord, not caused by svite.
See here for a brief description sveltejs/svelte#4934
For routify goto, please follow the documented approach: https://routify.dev/docs/helpers#goto
See here for an example with the url helper: https://github.com/dominikg/svite/blob/master/examples/routify-mdsvex/src/pages/_folder.svelte