You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`rewrites` is an async function that expects to return either an array or an object of arrays (see below) holding objects with `source` and `destination` properties:
), rewrites is an async function. The examples, however, neither await anything, nor explicitly return a promise.
JavaScript of course wraps the return value in a promise, so this works, but it may be considered bad form. And some of us have our linters turned up to 11.
Is there any context that might help us understand?
I ran an automated installation script for PostHog, which added this configuration and produced an eslint failure, and that led me to noticing this in the Next.js documentation.
I know that it's trivial to work around and I have done so, but I thought it might be worth considering changing the docs.
Does the docs page already exist? Please link to it.
In javascript async functions don't need to have an await inside them, like you've said the return value is implicitly wrapped in a promise.
I believe it's an async function because you might want to do something asynchronous before applying the rewrite e.g. getting a users locale from a cookie and rewriting them to the correct localised URL.
I do agree that perhaps an example code snippet using asynchronous behaviour inside the rewrite would reduce confusion, though.
Yeah, I'm assuming I am unusual for turning every linter rule up to 11 and enforcing zero warnings in my pre-commit hook (I have a greenfield project so I thought it would be nice to prevent any jank from creeping in). I just changed mine to
returnPromise.resolve([...
but I don't know if doing that in the docs would actually confuse more people than it will help.
Anyway, definitely not making any demands or even expressing a strong opinion, just bringing this up in case the maintainers felt like taking it into account.
What is the documentation issue?
Per
next.js/docs/01-app/04-api-reference/05-config/01-next-config-js/rewrites.mdx
Line 39 in a41152e
next.js/packages/next/src/server/config-shared.ts
Line 727 in a41152e
rewrites
is an async function. The examples, however, neitherawait
anything, nor explicitly return a promise.JavaScript of course wraps the return value in a promise, so this works, but it may be considered bad form. And some of us have our linters turned up to 11.
Is there any context that might help us understand?
I ran an automated installation script for PostHog, which added this configuration and produced an eslint failure, and that led me to noticing this in the Next.js documentation.
I know that it's trivial to work around and I have done so, but I thought it might be worth considering changing the docs.
Does the docs page already exist? Please link to it.
https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites
The text was updated successfully, but these errors were encountered: