我有一个React/Redux应用程序,在本地存储中跟踪用户的身份验证状态。该应用程序也设置了服务器端渲染。当渲染初始应用程序状态时,我遇到了问题。我的服务器创建了一个新的store并发出SET_INITIAL_STATE操作。客户端的初始操作读取localStorage,并将已验证的信息传递给我的reducers。然而,由于我在本地存储中使用无状态JWT进行身份验证,因此服务器对这个登录状态一无所知。
由于此时服务器和客户端不同步,我遇到了以下错误:
"React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:"
这是有道理的,因为服务器正在尝试渲染未经身份验证的状态。
针对仅依赖于客户端访问的状态,接受的标准或实践是什么?
由于此时服务器和客户端不同步,我遇到了以下错误:
"React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:"
这是有道理的,因为服务器正在尝试渲染未经身份验证的状态。
针对仅依赖于客户端访问的状态,接受的标准或实践是什么?