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

Bug: Infinite redirect on revalidation #1467

Closed
3 tasks done
wottpal opened this issue Oct 25, 2024 · 1 comment
Closed
3 tasks done

Bug: Infinite redirect on revalidation #1467

wottpal opened this issue Oct 25, 2024 · 1 comment
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@wottpal
Copy link

wottpal commented Oct 25, 2024

Description

Hey, there I wanted to share a reproduction of an issue that caused me several hours of debugging in the last days to locate. (I found it finally) πŸ˜΅β€πŸ’«

These are the changes I made from next-intl/examples/example-app-router/examples:

  1. Updating dependencies & to Next.js 15 (incl. async params, etc.). Don't know if this is v15-specific, just wanted to have the same environment as on in my project where the issue occured. Btw feel free to use this commit to upgrade the example for everyone.
  2. Adding an /api/revalidate route that basically only calls revalidatePath('/[locale]', 'page') (same issue with revalidatePath('/de'))
  3. Adding the bug reproduction in this commit:
    • Add export const dynamicParams = false in [locale]/layout.tsx (as all locales are statically known upfront)
    • Adding a return redirect('/') in the global not-found.tsx file (as that's the desired behavior for my app)

I now removed dynamicParams = false in my project. If it's generally advised against having it, I would suggest adding this to the docs!

Verifications

Mandatory reproduction URL

https://github.com/wottpal/next-intl-revalidation-bug-repro

Reproduction description

bun install
bun run build
NEXT_PRIVATE_DEBUG_CACHE=1 bun run start

# In a different terminal
curl -X POST http://localhost:3000/api/revalidate

Now open http://localhost:3000/de and you'll see an indefinite redirect occur.

Expected behaviour

Just loading the page as normal with an invalidated cache.

@wottpal wottpal added bug Something isn't working unconfirmed Needs triage. labels Oct 25, 2024
@amannn
Copy link
Owner

amannn commented Oct 25, 2024

Thanks for the detailed description!

So, as far as I understand, this is the issue:

  1. You have a dynamic segment like [locale] that uses generateStaticParams to be built statically
  2. You invalidate the segment later using revalidatePath
  3. Due to dynamicParams = false, the segment doesn't rebuild on the next visit

In your case, the returned 404 from dynamicParams = false will in turn call the redirect, but I guess that's secondary.

So is the bug really that revalidatePath doesn't schedule a recreation of the affected pages? Maybe you want to report that upstream in the Next.js repo, I think next-intl can't do much about it. Have you checked if there are already bug reports about this?

  1. Btw feel free to use this commit to upgrade the example for everyone.

That's kind of you, thanks! I'm currently waiting with upgrading to Next.js 15 due to #1442.

I'll close this issue since it seems to be an issue in Next.js, hope that sounds right to you!

@amannn amannn closed this as completed Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants