Skip to content
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

Update docs (nextjs, next.config.js) #884

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yongsk0066
Copy link

@yongsk0066 yongsk0066 commented Jun 23, 2023

Summary

I've made a small contribution aimed at addressing an issue noted in #860. The problem was concerning the possibility of a TypeError occurring in the next.config.js example code provided in the svgr documentation.

In the original example code:

const fileLoaderRule = config.module.rules.find((rule) =>
  rule.test?.test?.('.svg'),
)

If rule.test is not an instance of RegExp but some other type that does not have the .test method, a TypeError occurs as such:

TypeError: rule?.test?.test is not a function
...

To prevent this error, I've introduced a type check to see if rule.test is an instance of RegExp, thus making the code more robust and error-proof.

Here's the updated code snippet:

const fileLoaderRule = config.module.rules.find(
  (rule) => rule.test && rule.test instanceof RegExp && rule.test.test(".svg")
);

With this modification, the aforementioned TypeError can be effectively prevented, increasing the reliability and usability of the example code. This change contributes to the resolution of issue #860.

Test plan

To demonstrate the solidity of the code changes, the following steps will be executed:

Install Next.js version 13 or higher.
Follow the instructions provided in the documentation to set up and configure the next.config.js file.
Set up SVGR according to the documentation.
Run the application.

@vercel
Copy link

vercel bot commented Jun 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svgr ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2023 8:52am

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.

2 participants