Component Reinitialization Issue with loading.tsx
and revalidateTag
#66029
Labels
bug
Issue was opened via the bug report template.
create-next-app
Related to our CLI tool for quickly starting a new Next.js application.
locked
Pages Router
Related to Pages Router.
Link to the code that reproduces this issue
https://github.com/nikolay-gipp-sibe/nextjs-loading-revalidate-issue
To Reproduce
npm install
npm run dev
Open the project in your browser:
Navigate to http://localhost:3000/
Click on the button on the page:
You will find a button labeled "Click me".
In the browser console, you will see the logs from useEffect being displayed again, indicating the re-initialization of the LifecycleLogger component. The logs should show "Component mounted" again, followed by "Component unmounted" if the component was reinitialized.
Current vs. Expected behavior
Current Behavior:
When the
loading.tsx
file is present in the project:Clicking the button that calls
revalidateTag
causes theuseEffect
inLifecycleLogger
to run again on the first click, leading to re-initialization of the component.Subsequent clicks do not cause
useEffect
to run again, and the component behaves as expected after the first click.When the
loading.tsx
file is not present:The
useEffect
inLifecycleLogger
runs only once on the initial render.Clicking the button does not cause
useEffect
to run again, and the component behaves as expected.Expected Behavior:
The useEffect in LifecycleLogger should run only once on the initial render, regardless of the presence of loading.tsx.
Clicking the button that calls
revalidateTag
should not cause theuseEffect
to run again, preventing re-initialization of theLifecycleLogger
component on the first click when loading.tsx is present.Provide environment information
Which area(s) are affected? (Select all that apply)
create-next-app, Pages Router
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: