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
routeChangeComplete event is emitted for initial page load when fallback rewrite is enabled #34277
Comments
Could you link to this documentation please? 🙏 That event is supposed to be called when a page transition has completed.
https://nextjs.org/docs/api-reference/next/router#routerevents For the latter, the reason rewrites emits the event is because of the second render as explained here: (This is admittedly not in on our matching docs page as of writing, since it was recently clarified in #34049 but will be deployed 🔜) Closing as this is expected. |
By "documented elsewhere", I was referring to this issue: #4662 But to clarify, as I understand it: the expected behavior is for
If I'm reading this correctly, the flow goes something like this:
If so, now I understand why it's behaving this way.
It may be expected, but is it intuitive or convenient for users of this software? Some things I don't like about how it behaves right now:
|
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.10
What version of Node.js are you using?
16.13.0
What browser are you using?
Chrome
What operating system are you using?
macOS Monterey 12.1
How are you deploying your application?
Vercel
Describe the Bug
In a fresh Next project, the router does not emit a
routeChangeComplete
event for the initial page load, as documented elsewhere:But if you modify the
next.config.js
to include a fallback rewrite, the router DOES emit arouteChangeComplete
event for the initial page load:This behavior is inconsistent and makes it difficult to know when to expect the "extra" initial event for analytics purposes.
Expected Behavior
I would like the router events to behave consistently and intuitively. Personally I would prefer if the initial page load always emitted the event, but ultimately I just want it to be consistent so we're not surprised by the behavior.
To Reproduce
I have created a fresh NextJS 12 TypeScript repo and modified it to demonstrate the behavior: https://github.com/lafiosca/nextjs-initial-route-example
The changes I made are simple: lafiosca/nextjs-initial-route-example@290e372
I configured a catch-all fallback rewrite to an arbitrary host, as described in the Incremental Adoption example here: https://nextjs.org/docs/migrating/incremental-adoption
And then I added a listener for
routeChangeComplete
in_app.tsx
which outputs the url.I ran the project in local dev mode, opened it in Chrome, and viewed the console:
If you comment out the single entry from the
fallback
config and restart the server:You'll see a different behavior:
The text was updated successfully, but these errors were encountered: