- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用 React-MUI 为现有项目设置服务器端渲染。除了样式之外,我们已经完成了所有工作。我们的 CSS 不会为服务器端渲染加载。任何内联 CSS 都可以正常工作,但任何在文件开头定义并与 export default withStyles(styles)(Page)
绑定(bind)的工作表不工作。
我们的样式定义如下:
const styles = (theme) => ({
root{
//some CSS Here ...
}...
});
然后必然会倾倒 Prop
export default typeof window !== 'undefined'
? withRouter(connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(Home)))
: withStyles(styles)(Home);
并访问
const {classes} = this.props;
//then in render
<div className={classes.root}>...</div>
classes.someClassName
都没有CSS 在服务器端渲染中工作,但我们在浏览器中渲染它的第二个功能正常。当前的想法是尝试使用
<ThemeProvider/>
来自 MUI 的包装器,但任何建议都值得赞赏。
最佳答案
感谢@ReedDunkle 提供这方面的指导。最终使用他的 linked guide 让它工作起来作为引用。我最终只需要添加 sheets.collect(...)
以及 css = sheets.toString()
然后在 HTML 文档的标题中包含 CSS。不需要 ThemeProvider
,使用 WithStyles
连接起来都很好现在。
所以基本上它看起来像:
const html = renderToString(sheets.collect(<App/>));
const css = sheets.toString();
//...
//In your SSR HTML
<head>
<style id="jss-server-side">${css}</style>
...
</head>
...
<div id=react-root>{html}</div>
关于reactjs - MUI React SSR 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65999490/
很好,我在一台通过PM2执行的阿帕奇服务器上运行了一个带有ANGLE Universal的Web。。进行更改时,我会生成新版本的Web、将文件上传到主机并重新启动PM2任务。但当访问网络时,这些变化不
我在使用快速服务器构建和提供 Angular Universal 应用程序以获得良好的 SEO 方面遇到了挑战。 当我使用带有命令 "dev:ssr": "ng run motif:serve-ssr
我想在我的 nuxt 项目中使用一个 stencil 库。 我能够让它工作,但是当 vue 组件在服务器端呈现时,我只能让 stencil 的组件呈现在客户端。 我认为最大的问题是 defineCus
我想将我的sveltekit SSR应用托管到AWS服务(Amplify)。我们怎么能做到这一点呢?如果我们使用适配器静态,它是否会影响SSR?如果我们可以使用任何其他AWS服务来托管我们的svelt
我想为我的用户对我的应用进行 SSR。 但我的应用程序代码使用 useEffect 来检测用户屏幕宽度的大小,然后才呈现应用程序。 类似于: App.js // THE LAYOUT INITIA
我正在尝试制作一个 SSR react 应用程序,但无法将 Prop 从 express 传递到组件。 我在做什么错? server.js import AppPage2 from './src/pr
我使用 webpack 捆绑了我的 SSR 存储库(类似 inferno-react 的 lib)。它有 2 个路由文件,1 个用于服务器,1 个用于客户端,完全相同,但使用 require.ensu
当我用react做SSR时,发送给客户端的内容是如何构造的? 它是否等待异步操作完成? 是否等待状态树中的所有组件是否以某种方式保持稳定? 它会在某些生命周期方法中等待异步代码,例如用 await/a
我正在尝试创建一个 Angular 服务,组件可以使用该服务来观看窗口大小调整事件。经过多次尝试,我终于发现这个解决方案效果最好 https://stackoverflow.com/a/4383381
我正在重构一个大量使用 vue 组件的网络应用程序。 目前,vue 组件是使用 twig 模板语言在服务器端呈现的。组件作为静态 html 呈现给页面......没有使用 webpack 或 vue
我是 kibana 的新手,我想知道 kibana 如何在仪表板上生成可视化? 即 是否使用 SSR 生成图形/饼图等? 它是否使用 elastic-charts/charts.js/d3.js 等库
我的主代码 (app.component.html) 上没有任何会导致重新加载的更高级别的 NgIf。我正在使用 transferstate,因此在 SSR 设置公共(public) url 的答案后
我是 flutter 的新手,我想为我的 flutter Web 应用程序实现 SSR。 Flutter web 是否支持 SSR(服务器端渲染)? 我应该如何实现它? 最佳答案 尚未实现,但您可以在
我想知道是否有人可以向我指出如何为 vue SSR(服务器端渲染)设置包裹的资源或示例。 或者包裹不能使用Vue SSR? 最佳答案 应该像安装所需的各种库一样简单: # Yarn $ yarn ad
我使用 Angular SSR,当我刷新页面时,它首先进入登录页面,然后进入所需页面。 我还使用 cookie 来存储 token 。 canActivate( route: ActivatedRou
我在 SSR 上运行的异步管道有问题。没有错误,只有无限循环(似乎服务器正在等待 observable 被解析)。 我在用: @nestjs/ng-universal Angular 9 Fireba
以下内容适用于通过 NextJS 的 SSR。 我正在使用 React 的上下文来跟踪某些已安装组件的 ID。要点是 class Root extends React.Component { ge
我使用 React、react-router、@loadable/component 创建了一个项目。 现在我正在尝试将 SSR 添加到该项目中。我使用react-router进行了服务器端渲染。 然
我是 Angular ssr 的新手,您可以看到下面的代码 问题 如果我直接进入客户端路由,首先会显示 Rendered by server 但很快它就会重新渲染页面并显示: Rendered by
当窗口未定义时,我一直在尝试测试 else block 。当我使用 Next.js 时,窗口在服务器端渲染 (SSR) 期间将是未定义的。目前我找不到办法做到这一点。 非常感谢任何帮助。 我已经尝试在
我是一名优秀的程序员,十分优秀!