Skip to content

fix: dedupe React in Vite config to resolve invalid hook call#232

Merged
hotlong merged 2 commits intomainfrom
copilot/fix-invalid-hook-call
Feb 10, 2026
Merged

fix: dedupe React in Vite config to resolve invalid hook call#232
hotlong merged 2 commits intomainfrom
copilot/fix-invalid-hook-call

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

react-router-dom v7's <Link> crashes with Cannot read properties of null (reading 'useContext') due to pnpm strict mode causing Vite's esbuild pre-bundler to create a separate React instance for the router's dependency chain.

  • Add resolve.dedupe: ['react', 'react-dom'] to apps/web/vite.config.ts, forcing all dependency chains to resolve to the same React module instance
resolve: {
  dedupe: ['react', 'react-dom'],
  alias: {
    '@': resolve(__dirname, 'src'),
  },
},

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectos Ready Ready Preview, Comment Feb 10, 2026 2:01am

Request Review

…ances

In pnpm strict mode, Vite's dependency pre-bundling can create
separate React module instances for different dependency chains
(e.g. react-router-dom importing its own React copy). This causes
"Invalid hook call" errors when Link/useContext tries to access
React internals from a different instance than the one rendering.

Adding resolve.dedupe ensures all packages resolve to the same
physical React module.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid hook call in AuthLayout component fix: dedupe React in Vite config to resolve invalid hook call Feb 10, 2026
Copilot AI requested a review from hotlong February 10, 2026 01:55
@hotlong hotlong marked this pull request as ready for review February 10, 2026 02:03
Copilot AI review requested due to automatic review settings February 10, 2026 02:03
@hotlong hotlong merged commit d6d4fdc into main Feb 10, 2026
4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses invalid hook call / useContext crashes in the apps/web admin console caused by pnpm strict mode leading Vite’s pre-bundler to resolve multiple React instances.

Changes:

  • Add resolve.dedupe: ['react', 'react-dom'] to the Vite config to force a single React module instance across dependency chains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants