Skip to content

fix: normalize the rawPath without locale before attempting to asserting the 404 page #448

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

Merged

Conversation

JanStevens
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Jun 21, 2024

🦋 Changeset detected

Latest commit: 8bb1728

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
open-next Patch
app-pages-router Patch
app-router Patch

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

Copy link

vercel bot commented Jun 21, 2024

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

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2024 7:13am

Copy link
Contributor

@khuezy khuezy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We might want to add i18n to the e2e app to better test these scenarios.

@JanStevens
Copy link
Contributor Author

Thanks! We might want to add i18n to the e2e app to better test these scenarios.

I've updated the examples/pages-routes project to include some i18n config. I looked at the current e2e and they would already cover this bug since they assert the data json calls are resolving.

Would that be sufficient enough?

@khuezy
Copy link
Contributor

khuezy commented Jun 24, 2024

Thanks for adding the configs. I think it'll be useful to test the actual internationalization of the e2e apps to, that is, to add [lang] folder, eg: https://github.com/vercel/next.js/tree/canary/examples/app-dir-i18n-routing/app/%5Blang%5D

@JanStevens
Copy link
Contributor Author

Thanks for adding the configs. I think it'll be useful to test the actual internationalization of the e2e apps to, that is, to add [lang] folder, eg: https://github.com/vercel/next.js/tree/canary/examples/app-dir-i18n-routing/app/%5Blang%5D

Hmm, looking at the example I'm not sure it would work seeing that the middleware takes care of all the i18n stuff with the app router. This means that I wouldn't know the i18n configuration to start with so my new "code" would never be executed 🤔

TBH not using the app router at all atm, we stick with good old Pages 🤷

@conico974
Copy link
Contributor

It shouldn't be necessary to change anything for app dir, the middleware rewrites should already be applied at this point

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a few issues with it.
Ideally we should also handle the locale:true|false options in Next config rewrite/redirect

// Add the locale prefix to the regex so we correctly match the rawPath
const optionalLocalePrefixRegex = !!RoutesManifest.locales.length
? `^/(?:${RoutesManifest.locales.map((locale) => `${locale}/?`).join("|")})?`
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This make pnpm run build fail for me, in case people don't have i18n it should be the same so ^/

@@ -22,12 +22,17 @@ export interface MiddlewareOutputEvent {
origin: Origin | false;
}

// Add the locale prefix to the regex so we correctly match the rawPath
const optionalLocalePrefixRegex = !!RoutesManifest.locales.length
? `^/(?:${RoutesManifest.locales.map((locale) => `${locale}/?`).join("|")})?`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cause an issue with 3 e2e test because of this, it should also include the default case (i.e. with no locales prefix)
image
For the next data test it is because of this https://github.com/sst/open-next/blob/9d632d1bd5c3a8d7e7bbd13ae9daaca68da9284e/packages/tests-e2e/tests/pagesRouter/data.test.ts#L13 It ends now with en.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the best approach here? Create a new pages app with i18n + additional e2e tests? 🤔 . It's expected that in this case it's en.json instead of index.json (but only if you have i18n settings).

It's a bit of a mess (on Next.js side)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a perfect world, yeah we should do something like that, but honestly just testing with en.json is probably enough

@conico974 conico974 merged commit 7931bee into opennextjs:main Jun 28, 2024
3 checks passed
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.

3 participants