Skip to content

fix: edge cases for custom react module resolution #2188

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

Merged
merged 11 commits into from
Jun 29, 2023
Merged

Conversation

orinokai
Copy link
Contributor

@orinokai orinokai commented Jun 26, 2023

Description

Fix to ensure that the default React module resolution is always used as a fallback when rendering Page Router routes.

This PR also guards against missing module paths in previous versions of Next by try/catching each call to require.resolve().

In addition, this PR fixes a case where paths with query strings caused the route matching to fail.

@orinokai orinokai requested a review from a team as a code owner June 26, 2023 10:09
@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/649d6f9f263f45000880f3eb
😎 Deploy Preview https://deploy-preview-2188--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/649d6f9fc102b300080200c7
😎 Deploy Preview https://deploy-preview-2188--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jun 26, 2023
@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/649d6f9ff0d6f200086e5d67
😎 Deploy Preview https://deploy-preview-2188--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/649d6f9fe0a26700080f243c
😎 Deploy Preview https://deploy-preview-2188--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/649d6f9f6d3c4a0008fc73e0
😎 Deploy Preview https://deploy-preview-2188--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/649d6f9f2faea60008d334e6
😎 Deploy Preview https://deploy-preview-2188--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/649d6f9f451a3a000828a673
😎 Deploy Preview https://deploy-preview-2188--next-plugin-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/649d6f9fb1f7d5000818263e
😎 Deploy Preview https://deploy-preview-2188--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jun 26, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 013b210
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/649d6f9fc102b300080200c2
😎 Deploy Preview https://deploy-preview-2188--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@orinokai orinokai marked this pull request as draft June 26, 2023 10:23
@orinokai orinokai marked this pull request as ready for review June 26, 2023 16:13
const resolvedPath = require.resolve(path, opts)
mode.set(hook, resolvedPath)
} catch {
// ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need any logging here for our observability or is it safe to just ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @MarcL, this is safe to ignore here because it's not actually an error - we want to delete the hook in this case because it happens when a module isn't found, i.e. an older version of Next
I have updated with a better comment, thanks

MarcL
MarcL previously approved these changes Jun 27, 2023
Copy link
Contributor

@MarcL MarcL left a comment

Choose a reason for hiding this comment

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

Question about logging but looks good otherwise.

try {
const resolvedPath = require.resolve(path, opts)
mode.set(hook, resolvedPath)
} catch {

Choose a reason for hiding this comment

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

Consider only deleting the hook when the error thrown is MODULE_NOT_FOUND, otherwise rethrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nickytonline good plan, have updated in 78fc4d6

@orinokai orinokai changed the title fix: use default react resolution for falsy env var fix: edge cases for custom react module resolution Jun 28, 2023
nickytonline
nickytonline previously approved these changes Jun 28, 2023
Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

🚢

@kodiakhq kodiakhq bot merged commit 6b527be into main Jun 29, 2023
@kodiakhq kodiakhq bot deleted the rs/react-env-var-fix branch June 29, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants