fix(core): Update with-routes to account for trailing slash or capitalizations when redirecting#2670
Conversation
🦋 Changeset detectedLatest commit: caa45fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
migueloller
left a comment
There was a problem hiding this comment.
Can we please get some regression tests for this fix @jordanarldt?
@migueloller For sure. I'll get that added in the morning. We don't currently have any test fixtures for creating 301 redirects, so I'll need to create some test fixtures / api clients, and then add a new functional test suite. It may use up some of my capacity but we definitely should have some tests for this. |
|
Do we not have the basics set up for spinning up Catalyst via Playwright and navigating to some URLs and then checking the response status code? If not, then that's definitely worth investing into! |
|
Based on this existing test, it seems like we're already set up to test something like this. https://github.com/bigcommerce/catalyst/blob/canary/core/tests/ui/e2e/not-found.spec.ts |
@migueloller The issue only replicates when you've created some specific 301 Redirects. In order to write a test for this, we need to be able to create the dynamic 301 redirects to a product via the test suites, which will require a fixture 👍 |
|
Ah I see. If we don't want to have to create the specific redirects for the BigCommerce API we could use Playwright's Mock APIs to mock the GraphQL request to include the relevant redirects? |
|
I think a fixture would be ideal, by the way. But I wanted to provide an option in case that was prohibitively complicated. |
6b7df76 to
32b598e
Compare
32b598e to
d47dbcb
Compare
…lizations when redirecting
d47dbcb to
caa45fc
Compare
migueloller
left a comment
There was a problem hiding this comment.
The tests are looking great! Thanks @jordanarldt 🙏🏻
…lizations when redirecting (#2670)
…lizations when redirecting (#2670)
What/Why?
Update the with-routes middleware to account for the
TRAILING_SLASHenv var, as well as capitalized letters in 301 Redirects.There was a reported issue where when using
TRAILING_SLASH=falsein the Catalyst environment variables, redirect loops could occur if you had a redirect going from/example-path -> /example-path/, or capitalizations like/some-url -> /some-URLTesting
Tested locally, confirmed fix works.
Regression test results before changes:
Regression test results after changes:
Before fix
Dynamic 301 Redirect from
/infinite-redirect-testto a product with the URL/infinite-redirect-test/whileTRAILING_SLASH=falseScreen.Recording.2025-11-05.at.4.54.51.PM.mov
Manual 301 Redirect from
/redirect-testto/redirect-TESTScreen.Recording.2025-11-05.at.4.55.46.PM.mov
After fix
Dynamic 301 Redirect from
/infinite-redirect-testto a product with the URL/infinite-redirect-test/whileTRAILING_SLASH=falseScreen.Recording.2025-11-05.at.4.59.30.PM.mov
Manual 301 Redirect from
/redirect-testto/redirect-TESTScreen.Recording.2025-11-05.at.5.00.23.PM.mov
Migration
Copy changes from
with-routes.tsusing this PR as a reference