Meteor 1.8 SSR Server Data Double Render [content flashes twice]
I would love to see if anyone in the community has any experience with this problem! I can’t seem to trouble shoot and solve.
Problem:
When we need to pull data from the server for a specific public facing page, the content loads an initial time and then re-loads causing the user to see a “flash” of content. I’m assuming this has to due with the sync in the client hydrate
but as this is my first Meteor SSR setup I’m a bit lost.
Here is an example live page: https://www.winkkitten.com/s/7QQcCHWgxWmewX4P3
React Component Code
componentWillMount () {
if (Meteor.isServer) {
var result = AtlasConnection.call('public.order.status', this.props.match.params.order)
this.setState({ order: res })
}
}
async componentDidMount () {
await AtlasConnection.call('public.order.status', this.props.match.params.order, (err, res) => {
if (!err) {
this.setState({ order: res })
}
}
}
render () {
if (!this.state.order) {
return (
<LoadingSpinnerHere />
)
}
return (
<ContentHere />
)
}
Client.js
const App = () => (
<Provider store={store}>
<StripeProvider apiKey={Meteor.settings.public.stripe.publishableKey}>
<Router history={history}>
<Switch>
<Routes />
</Switch>
</Router>
</StripeProvider>
</Provider>
)
onPageLoad(async sink => {
ReactDOM.hydrate(
<App />,
document.getElementById('wk')
)
})
Server.js
onPageLoad((sink) => {
const context = {}
const store = createStore(reducers, applyMiddleware(thunk))
const App = props => (
<Provider store={store}>
<StaticRouter location={props.location} context={context}>
<Routes />
</StaticRouter>
</Provider>
)
App.propTypes = {
location: object.isRequired
}
sink.renderIntoElementById('wk', renderToString(<App location={sink.request.url} />))
const helmet = Helmet.renderStatic()
sink.appendToHead(helmet.meta.toString())
sink.appendToHead(helmet.title.toString())
if (context.url) {
sink.redirect(context.url)
}
const preloadedState = store.getState()
sink.appendToBody(`
<script>
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\u003c')}
</script>
`)
})