-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behavior with Svelte contexts #809
Comments
I'm not able to reproduce the issue on my machine. Can you provide System Info?
|
Sure.
I'm also unable to reproduce the first issue on my machine. It only appends on Stackblitz. But after a bit more digging, I found out the second issue is caused by a circular dependency. I also updated the Svelte REPL (which seems to work fine with |
Just to sum up for easier reading:
|
I can't reproduce the second issue with object on Node 14.17 (with npm 6) and on Node 16.13.2 (with npm 8.1.2) - it logs But |
@sheremet-va it is using node 14.17 and the error on local I'm trying to reproduce |
|
Yes, I know, that's why I tried it. |
By default we are processing transformMode: {
web: [/\.svelte$/, /\.[jt]s$/]
} |
@sheremet-va your suggestion working also with node 16.13.0 (LTS) |
@sheremet-va seems like the |
Describe the bug
While trying to migrate from Jest, I found that managing a Svelte context from outside a component seems to create some strange issues with Vitest.
First issue:
Function called outside component initialization
Let's say I call Svelte's
setContext
in a function - let's call itinitContext
- and this function is defined in a.js
file beside the.svelte
component, if I callinitContext
inside my Svelte component Vitest will throwFunction called outside component initialization (setContext)
.According to the Svelte REPL it should work, but if you try it with Vitest, it doesn't.
Second issue: using an object defined in a
.js
file as context key returns anundefined
contextI actually stumbled on the first issue while trying to reproduce this one. I did manage to reproduce it on Stackblitz, but suddenly out of nowhere, the first issue appeared. So I guess I won't really have a repro for this one.
Using the same Stackblitz as before,
getContext
inHello.svelte
returnedundefined
. I figured out it was due to thecontextKey
being an object and being defined in another file (context.ts
). If I change the value ofcontextKey
toexport const contextKey = "myContext"
, it suddenly works perfectly (like in the Svelte REPL).I guess Vitest is doing something with the imports which somehow redefines
contextKey
, thus makingcontextKey === contextKey
false.BTW using objects/symbols as context key is the recommended way according to the Svelte doc.
Reproduction
https://stackblitz.com/edit/github-zrwj6k-isnfa8?file=components%2Fcontext.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: