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

Component Reinitialization Issue with loading.tsx and revalidateTag #66029

Closed
nikolay-gipp-sibe opened this issue May 21, 2024 · 2 comments · Fixed by #66538
Closed

Component Reinitialization Issue with loading.tsx and revalidateTag #66029

nikolay-gipp-sibe opened this issue May 21, 2024 · 2 comments · Fixed by #66538
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.

Comments

@nikolay-gipp-sibe
Copy link

nikolay-gipp-sibe commented May 21, 2024

Link to the code that reproduces this issue

https://github.com/nikolay-gipp-sibe/nextjs-loading-revalidate-issue

To Reproduce

  1. npm install

  2. npm run dev

  3. Open the project in your browser:
    Navigate to http://localhost:3000/

  4. Click on the button on the page:
    You will find a button labeled "Click me".

  5. 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 the useEffect in LifecycleLogger 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.

With loading tsx

When the loading.tsx file is not present:

The useEffect in LifecycleLogger runs only once on the initial render.
Clicking the button does not cause useEffect to run again, and the component behaves as expected.

Without loading tsx

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 the useEffect to run again, preventing re-initialization of the LifecycleLogger component on the first click when loading.tsx is present.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 61293
  Available CPU cores: 16
Binaries:
  Node: 22.1.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

@nikolay-gipp-sibe nikolay-gipp-sibe added the bug Issue was opened via the bug report template. label May 21, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Pages Router Related to Pages Router. labels May 21, 2024
@gaojude
Copy link
Contributor

gaojude commented May 22, 2024

Should be fixed by #66061

ztanner added a commit that referenced this issue Jun 4, 2024
When `router.refresh` or a server action creates a new `CacheNode` tree,
we were erroneously not copying over the `loading` segment in the new
tree. This would cause the subtree to be remounted as the loading
segment switched from having a Suspense boundary to not having one.

Fixes #66029
Fixes #66499
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.
Projects
None yet
2 participants