fix(performance): dedupe React dependencies and cache lazy loaded category components - #1028
Merged
DavidHDev merged 1 commit intoAug 6, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes local-dev “Invalid hook call” errors caused by duplicate React runtimes in Vite resolution, and prevents unnecessary unmount/remount behavior on CategoryPage by stabilizing React.lazy() component identities across renders.
Changes:
- Add Vite
resolve.dedupeforreactandreact-domto ensure a single React instance is used. - Cache
React.lazy()results at module scope inCategoryPageso the rendered subcategory component reference remains stable across re-renders.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| vite.config.js | Forces Vite to dedupe react and react-dom to avoid duplicate runtime instances and hook call errors. |
| src/pages/CategoryPage.jsx | Adds a module-level lazy-component cache to prevent remounts caused by re-creating React.lazy() on each render. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Bug
When Vite resolves multiple or duplicate instances of
reactandreact-domduring module resolution or dynamic imports, React throws anUncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.Fixes #1029
PR Summary
This PR addresses duplicate React dependency issues and fixes unwanted component remounting during route renders on
CategoryPage.Changes Included
vite.config.js):dedupe: ['react', 'react-dom']underresolveto ensure single instance resolution of React across all imports/dependencies.src/pages/CategoryPage.jsx):lazyComponentCache(Map) to cacheReact.lazy()component factories.lazy()instantiation during render with cached lookup to maintain stable component references and avoid unnecessary unmounting/remounting on re-renders.Verification
npm run devto ensure no "Invalid hook call" warnings or duplicate React runtime errors occur.