question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rewrites with conflicting paths

See original GitHub issue

This is continued from the discussion in https://github.com/serverless-nextjs/serverless-next.js/issues/646

Reproduction here: https://github.com/patricktyndall/sls-next-bug-reproduction

Describe the bug

When rewrite paths conflict with /public or static routes in /pages, things start breaking.

Actual behavior

/dynamic-1, /login, and /my-test-asset.txt break

Expected behavior

/dynamic-1, /login, and /my-test-asset.txt don’t break

Steps to reproduce

Deploy using serverless

Versions

Additional context

This is important because it prevents existing next.js apps from using this component, as it breaks compatibility.

I added comments in next.config.js on what happens when you change the rewrites.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
dphangcommented, Oct 20, 2020

Yep, I do note that - just was trying to clarify how it’s implemented right now - it just takes the first matching rewrite and tries to rewrite it (it doesn’t know about no-ops, doesn’t know about existing non-dynamic pages or static/public files).

I did test the repro with the dev server and confirm your findings. Even with or without the no-op rewrite, it looks like next also doesn’t rewrite non-dynamic routes such as /login (so /:path* to /content/:path is not going to rewrite /login, as /login has priority).

However, for dynamic routes like /content/dynamic-1, the no-op rewrite seems to prevent those from being rewritten (your destination is /content/:path, so I changed this to something else to test this - either another internal route or external route).

I think this has helped cleared things out. So looks like there are two things to fix:

  1. Public/static files and non-dynamic pages should always be prioritized over rewrites, i.e they will never be rewritten. This is per Next.js documentation.
  2. No-op rewrite should be respected to try to first match to any existing route (including non-dynamic and dynamic routes), before doing any further rewrite. Documentation in Next.js seems to agree on this, although it’s a bit less clear as no-op rewrites are only mentioned in the context of external rewrites, but it applies to all kinds of rewrites.
0reactions
dphangcommented, Oct 21, 2020

Fixed and released in latest alpha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix & solve merge conflicts? - Tower Git Client
From time to time, merge conflicts will happen in any Git project. Here's a detailed guide on how to deal with them.
Read more >
Routes having conflict in URL rewriting or configuring route in ...
In my project I am providing REST API for mobile devices. But I am having a problem with configuring route for URLs of...
Read more >
Git merge conflicts | Atlassian Git Tutorial
What is a git merge conflict? A merge conflict arises when Git cannot automatically resolve code differences between two commits. Learn more here....
Read more >
how fix rewrite rule conflict - Webmasters Stack Exchange
The quick fix is to simply reverse these two directives, so the more specific rule (that matches exactly 2 path segments) is first....
Read more >
Resolve conflicts | IntelliJ IDEA Documentation - JetBrains
Under distributed version control systems, such as Git and Mercurial, conflicts arise when a file you have committed locally has changes to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found