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

Add note about beforeFiles continuing #27211

Merged
merged 2 commits into from
Jul 16, 2021
Merged

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Jul 15, 2021

This adds a note explaining that beforeFiles continue instead of checking the filesystem/dynamic routes immediately like they do in afterFiles and fallback.

Documentation / Examples

  • Make sure the linting passes

Closes: #26795

@kodiakhq kodiakhq bot merged commit 6e99f7a into vercel:canary Jul 16, 2021
@ijjk ijjk deleted the docs/before-files branch July 16, 2021 16:20
@threehams
Copy link

#26795 is about rewrites looping through all beforeFiles, then continuing on to match afterFiles despite already hitting a match. Is this intended? It complicates the approach used in #12848 to support white-label sites (requires additional rewrites for ambiguous routes), and doesn't seem to match the documentation added in this PR.

@ijjk
Copy link
Member Author

ijjk commented Jul 16, 2021

@threehams looking at the reproduction provided in the mentioned issue the beforeFiles rewrite will not match before the afterFiles rewrites due to the destination in beforeFiles pointing to a dynamic route and dynamic routes aren't checked right after beforeFiles.

I added this note to mention the continuing behavior of beforeFiles, if there's anything we could add to make this more clear let me know. Potentially we could give more examples of when things are matched/checked 🤔

@threehams
Copy link

Let me see if I can get you a better reproduction. Should I comment on the same issue or open a new one?

@ijjk
Copy link
Member Author

ijjk commented Jul 16, 2021

The existing reproduction explains the issue correctly, it's not a bug and is meant to match that way for a dynamic route. If you were to set this line to fallback rewrites instead it would work as fallback rewrites are run after checking dynamic routes and all Next.js paths, afterFiles comes before dynamic routes are checked.

If you were to change this line to point to a non-dynamic page instead it would also work since non-dynamic pages are checked before afterFiles rewrites.

Let me see if I can tweak this doc to explain this order a bit more

@ijjk
Copy link
Member Author

ijjk commented Jul 16, 2021

@threehams I opened an additional PR here adding some additional context, let me know if this helps clear it up some more or if it could use some more information to help make this more clear

kodiakhq bot pushed a commit that referenced this pull request Jul 16, 2021
This expands on #27211 and lists the full routes order used in Next.js to allow more exact matching when leveraging the different rewrite priorities. 

## Documentation / Examples

- [x] Make sure the linting passes
flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
This adds a note explaining that `beforeFiles` continue instead of checking the filesystem/dynamic routes immediately like they do in `afterFiles` and `fallback`. 

## Documentation / Examples

- [x] Make sure the linting passes

Closes: vercel#26795
flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
This expands on vercel#27211 and lists the full routes order used in Next.js to allow more exact matching when leveraging the different rewrite priorities. 

## Documentation / Examples

- [x] Make sure the linting passes
@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
created-by: Next.js team PRs by the Next.js team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrites in beforeFiles result in 404 errors when a afterFiles also contains a matching rewrite.
3 participants