-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Changes in files injected with useContext() force vite-react project for full reload #2624
Comments
I found out that issue is some how related to useContext(). When i import store directly, it works properly. But when i inject it with react context it does a full reload. |
@Relaxe111 Is there a solution to this problem? |
@patak-dev Is there a solution to this problem? |
I had the same issue. I was able to somehow solve it. When HMR is called, I find this error in the console with the following message:
After some search, here is the issue on SO. let container: HTMLElement | null = null;
document.addEventListener("DOMContentLoaded", function () {
if (!container) {
container = document.getElementById("root");
if (!container) {
console.log("No root element is found.");
} else {
const root = createRoot(container);
root.render(
<StrictMode>
<StoreContextProvider>
<CustomRouter history={history}>
<App />
</CustomRouter>
</StoreContextProvider>
</StrictMode>
);
}
}
}); After I made this change, I can say that my app loading is way faster than the default implementation. |
React context is a great feature, however few issues related to react context from 2020, 2021 did not get resolved, i dont think vite is a good develeopment tools for react project, unless you dont using react context... |
Closing as I confirmed this works after upgrading plugin-react-refresh to plugin-react. related: #3301 |
When I change something in a .ts file it force to full reload the application, with losing the state of the application.
This is NOT related to mobx-state-tree, this happens even if i add a simple const test = 'test' field in any part of the .ts file.
I tried to migrate a big project to vite and it take long time to reload for each change in any .ts file, also after a while it hangs and wait for server to respond and it never updates. I think this is related to this issue.
repo with the issue example: https://github.com/Relaxe111/vite-react-mst
vite
version: 2.1.2The text was updated successfully, but these errors were encountered: