-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Context value populated incorrectly when created using a helper function. #480
Comments
Seems like the lowest friction solution to preactjs#480
I have a similar issue, but I don't use any helper function to create context. Here is more information (reproduction repo, how to reproduce, ...): vitejs/vite#12681 |
This is basically the offending line https://github.com/preactjs/prefresh/blob/main/packages/babel/src/index.mjs#L495 it is used to create an intermediary that is used to maintain the context-value. This because when we have a file like const x = createContext();
// Do something in a component with context The value that was updated throughout the lifetime of the application would get lost as createContext gets re-invoked and the closure of the Component would pick up a new context to track. I'm currently thinking about better solutions for this. One of the things I can see working: #488 The issue you are faced with @AleksaStevic is a bit different as normally we are taking the EDIT: yes the |
Stackblitz reproduction of error here. My setup uses Vite.
I sometimes use a helper function that wraps calls to
createContext
. An example is thecreateContextWithoutDefault
function in the Stackblitz. As a consequence of this, Prefresh appears to fill the context with the wrong value when it should instead be empty. For example (as seen in the Stackblitz):Inside
<Test />
, Context B has the value"Context A"
—but a value for Context B was never provided!I've inferred from looking around the issues here that there is some magic done to uniquely identify each
createContext
call. I suppose that breaks when you wrapcreateContext
like this. That makes sense, but it's pretty unfortunate, especially because it fails silently. This produced an issue for us that we couldn't repro locally (well at least we couldn't repro it locally in dev mode).Is there anything that can be done here?
createContextWithoutDefault
to explicitly generate a unique ID for Prefresh?createContext
is called inside a function (as opposed to at the module top level)?Thanks in advance!
The text was updated successfully, but these errors were encountered: