Yêu cầu thg 7 16, 4:37 SA 110 0 1
  • 110 0 1
+1

NextJS: Tại sao phải khởi tạo store mới với mỗi request? tại sao single store có thể gây rò rỉ dữ liệu?

Chia sẻ
  • 110 0 1

Từ ChatGPT:

  • Server có thể cập nhật redux store (vd: từ client A update dữ liệu thông qua server action sau đó server sửa lại redux store) nên là việc client A có thể truy cập dữ liệu của client B thông qua global store.
  • Nếu theo như trên thì chỉ cần không thay đổi store trên server thì sẽ không có khả năng rò rỉ dữ liệu

SSR-friendly store hydration: Next.js applications are rendered twice, first on the server and again on the client. Failure to render the same page contents on both the client and the server will result in a "hydration error". So the Redux store will have to be initialized on the server and then re-initialized on the client with the same data in order to avoid hydration issues.

No global stores - Because the Redux store is shared across requests, it should not be defined as a global variable. Instead, the store should be created per request.

Thảo thuận có thể liên quan:

1 CÂU TRẢ LỜI


Đã trả lời thg 7 24, 11:03 SA
+1
Chia sẻ
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí