如何修复“首次加载时闪烁”?

时间:2019-05-23 16:38:15

标签: css reactjs meteor ssr

添加SSR后,重新加载页面时,我的样式开始闪烁。 我究竟做错了什么?另外,这里描述了此问题:https://github.com/meteor/meteor/issues/9758#issuecomment-381154274

我遵循的指示:https://docs.meteor.com/packages/server-render.html

这是我的服务器/index.js:

import React from 'react'
import { renderToString } from 'react-dom/server'
import '/app/api/methods'
import App from '/app/components/app'
import importFaqQuestions from './importFaqQuestions'

import { Helmet } from 'react-helmet'

import { onPageLoad } from 'meteor/server-render'

onPageLoad((sink) => {
    const helmet = Helmet.renderStatic()
    sink.renderIntoElementById('app', renderToString(<App location={sink.request.url}/>))
    sink.appendToHead(helmet.meta.toString())
    sink.appendToHead(helmet.title.toString())
    sink.appendToHead(helmet.link.toString())
    sink.appendToHead(helmet.script.toString())
}) 

这是我的风格

import React from 'react'
import { Meteor } from 'meteor/meteor'

import { PagesRoutes } from '/mightyor/components/PagesRoutes'

if (Meteor.isClient) {
    import('./app.import.less')
}

const App = () => (
    <PagesRoutes/>
)

export default App

这会使应用程序中的所有样式在首次加载时都闪烁

0 个答案:

没有答案