Reactjs collectStyles未从styled components SSR中的根应用程序组件获取样式

Reactjs collectStyles未从styled components SSR中的根应用程序组件获取样式,reactjs,styled-components,Reactjs,Styled Components,我正在为我的react应用程序使用样式化组件。当我们在客户端添加样式化组件时,它工作正常,但在SSR期间,ServerStyleSheet.collectStyles无法从根应用程序组件获取样式。当我将GlobalStyle与根应用程序组件一起使用时,collectStyles会获取全局样式的样式,但不会从根应用程序组件获取样式 html = renderToString(sheet.collectStyles( <Loadable.Capture report={modu

我正在为我的react应用程序使用样式化组件。当我们在客户端添加样式化组件时,它工作正常,但在SSR期间,ServerStyleSheet.collectStyles无法从根应用程序组件获取样式。当我将GlobalStyle与根应用程序组件一起使用时,collectStyles会获取全局样式的样式,但不会从根应用程序组件获取样式

html = renderToString(sheet.collectStyles(
        <Loadable.Capture report={moduleName => modules.push(moduleName)}>
          <Provider store={store}>
            <StaticRouter location={req.url} context={context} history={history}>
              <React.Fragment>
                <App />
                <GlobalStyle/>
              </React.Fragment>
            </StaticRouter>
          </Provider >
        </Loadable.Capture>
      ));
使用下面的代码,我无法获得任何样式

html = renderToString(sheet.collectStyles(
        <Loadable.Capture report={moduleName => modules.push(moduleName)}>
          <Provider store={store}>
            <StaticRouter location={req.url} context={context} history={history}>
              <React.Fragment>
                <App />
              </React.Fragment>
            </StaticRouter>
          </Provider >
        </Loadable.Capture>
      ));
html=renderString(sheet.collectStyles)(
modules.push(moduleName)}>
));
通过这段代码,我可以获得GlobalStyle的样式,但无法获得根应用程序组件的样式

html = renderToString(sheet.collectStyles(
        <Loadable.Capture report={moduleName => modules.push(moduleName)}>
          <Provider store={store}>
            <StaticRouter location={req.url} context={context} history={history}>
              <React.Fragment>
                <App />
                <GlobalStyle/>
              </React.Fragment>
            </StaticRouter>
          </Provider >
        </Loadable.Capture>
      ));
html=renderString(sheet.collectStyles)(
modules.push(moduleName)}>
));