+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?
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:
Thêm một bình luận