You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when I try to access the context, I get an error because is reset to null:
import{createContext,useContext}from"react";exporttypeTheme="dark"|"light";exportconstThemeContext=createContext<Theme|null>(null);exportfunctionuseTheme(){consttheme=useContext(ThemeContext);if(!theme){thrownewError('"ThemeContext" was not available');}returntheme;}
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
This is an expected behavior. It's important to note that you have src/context.tsx imported from two worlds, namely inside and outside of vite ssr module graph:
Describe the bug
I'm not fully sure if this is a bug or is how it works.
I have a react tree with a context on top:
The
App
is an export from a virtual module:But when I try to access the context, I get an error because is reset to null:
Reproduction
https://github.com/Neo-Ciber94/vite-ssr-react-context-issue
Steps to reproduce
yarn install
andyarn dev
System Info
Used Package Manager
yarn
Logs
Error: "ThemeContext" was not available
at Module.useTheme (.../src/context.tsx:10:11)
at App (virtual:app:8:39)
Validations
The text was updated successfully, but these errors were encountered: