简体   繁体   English

将 Redux 开发工具与 NextJS 一起使用:当 Redux 被称为服务器端时,如何找出商店中发生了什么?

[英]Using Redux dev tools with NextJS: how to find out what's going on in store when Redux is being called server side?

We have a NextJS application using next-redux-wrapper and Redux thunks.我们有一个使用next-redux-wrapper和 Redux thunk 的 NextJS 应用程序。 We have a page that works fine when we load the page via a local link, that is, it's rendered locally, but when we reload the page, thus rendering it on the server, our store remains (partially) empty: certain fields are never filled.当我们通过本地链接加载页面时,我们有一个页面可以正常工作,也就是说,它在本地呈现,但是当我们重新加载页面,从而在服务器上呈现它时,我们的存储(部分)保持为空:某些字段永远不会填充。

I'm using Redux dev tools to follow the actions, but all I ever see when I reload the page in the list of actions is @@init .我正在使用 Redux 开发工具来跟踪操作,但是当我重新加载操作列表中的页面时,我所看到的只是@@init When I put log statements in I see -- in the server-side console -- that my reducer is being called with valid values.当我将日志语句放入时,我看到 - 在服务器端控制台中 - 我的减速器正在使用有效值调用。 However that field remains empty in the store, as shown by RDT in the browser.但是,该字段在商店中仍然为空,如浏览器中的 RDT 所示。

The Redux actions are not showing up in the browser Redux Dev Tools console because they are happening on the server. Redux 操作未显示在浏览器 Redux 开发工具控制台中,因为它们发生在服务器上。

Redux 开发工具显示的内容

我的日志语句显示的内容

The store is set up as next-redux-wrapper instructs商店设置为next-redux-wrapper指示

// _app.ts
import withRedux from 'next-redux-wrapper';
import initStore from '../redux/store';

const makeStore = initialState => {
  return initStore(initialState);
};

const MyApp = ({ Component, pageProps, apollo, store }: Props) => {
  return (
    <ApolloProvider client={apollo}>
      <Provider store={store}>
        <Sidebar />
        <Component {...pageProps} />
      </Provider>
    </ApolloProvider>
  );
};

MyApp.getInitialProps = async appContext => {
  const { Component, ctx } = appContext;
  const appProps = await App.getInitialProps(appContext);
  const pageProps = Component.getInitialProps
    ? await Component.getInitialProps(ctx)
    : {};

  const allProps = {
    ...appProps,
    ...pageProps
  };
  return { ...allProps };
};
export default withRedux(makeStore)(withApollo(MyApp));

How can I figure out what's happening in my Redux store if I can't use Redux Dev Tools to see?如果我无法使用 Redux 开发工具查看,我如何才能弄清楚我的 Redux 商店中发生了什么? What I'd like to do is find out exactly where and when the values that are being passed to the reducers are overwritten with a blank value.我想做的是准确找出传递给减速器的值在何时地被空白值覆盖。

The answer turned out to be that I was dispatching a thunk within my thunk server side, and I suppose that the result didn't come back in time to make it to the store transfer from NextJS server to the client.答案原来是我在我的 thunk 服务器端调度了一个 thunk,我想结果没有及时返回以使其从 NextJS 服务器到客户端的存储传输。 When I made it a direct, async, call within my thunk, all worked fine.当我在我的 thunk 中将其设为直接的异步调用时,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM