vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.33k stars 26.51k forks source link

Layout is re-rendered when server action is called #66961

Open festusyuma opened 2 months ago

festusyuma commented 2 months ago

Link to the code that reproduces this issue

https://github.com/festusyuma/next-issue-test

To Reproduce

  1. start application in dev mode

  2. navigate to url

  3. click on the next buttom

  4. log on layout will be printed for almost every click to indicate the layout was rendered again on the server

  5. checkout to react-hook-form and repeat steps 1 - 4, same thing will happen when using react-hook-form

  6. checkout to react-hook-form-api and repeat 1-4, this will not re-render the layout when calling external api

https://photos.app.goo.gl/L2faEJPxTYDUibeBA (video sample)

Current vs. Expected behavior

Expected behaviour: Layout should not be re-rendered when server action is called Current behaviour: Layout is re-rendered when server action is called. this happens even when you have children and grandchildren layout. it is re-rendered from top to bottom

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Thu May 30 21:30:12 PDT 2024; root:xnu-11215.0.31.511.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: 8.15.8
Relevant Packages:
  next: 14.2.4 // Latest available version is detected (14.2.4).
  eslint-config-next: 14.2.4
  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, Developer Experience, Performance

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), Other (Deployed)

Additional context

No response

InsightfulFuture commented 1 month ago

This appears to be resetting state in my app

techgerm commented 2 weeks ago

We're experiencing the same this as well - is this expected behavior?