-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
59 lines (51 loc) · 1.96 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import './appcache'
import './browser-policy'
import './fixtures'
import './connectors'
import React from 'react'
import { StaticRouter } from 'react-router'
import { renderToNodeStream } from 'react-dom/server'
import { onPageLoad } from 'meteor/server-render'
import { DataCaptureProvider } from 'meteor/npdev:collections'
import Loadable from 'react-loadable'
import s2s from 'string-to-stream'
import sq from 'streamqueue'
import { HelmetProvider } from 'react-helmet-async'
import { App } from '/imports/App'
h = React.createElement // eslint-disable-line
Loadable.preloadAll().then(() => onPageLoad(sink => {
// if cookie sssr (skip server side rendering) is set, don't bother with ssr
if (sink.request.cookies.sssr) return
const context = {}
const modules = []
const modulesResolved = []
const helmetContext = {}
const dataHandle = {}
const app = <DataCaptureProvider handle={dataHandle}>
<HelmetProvider context={helmetContext}>
<Loadable.Capture report={(moduleName) => { modules.push(moduleName) }}
reportResolved={(resolvedModuleName) => { modulesResolved.push(resolvedModuleName) }}>
<StaticRouter location={sink.request.url} context={context}>
<App />
</StaticRouter>
</Loadable.Capture>
</HelmetProvider>
</DataCaptureProvider>
const appStream = renderToNodeStream(app)
const queuedStreams = sq(
() => appStream,
() => s2s(`<script id="__preloadables__">__preloadables__=${JSON.stringify(modulesResolved)};</script>`),
() => s2s(dataHandle.toScriptTag())
)
sink.renderIntoElementById('root', queuedStreams)
// const { helmet } = helmetContext
// sink.appendToHead(helmet.meta.toString())
// sink.appendToHead(helmet.title.toString())
// sink.appendToHead(helmet.link.toString())
// WebApp.addHtmlAttributeHook(() => (
// Object.assign({
// lang: 'en'
// }, helmet.htmlAttributes.toComponent())
// ))
// :TODO: Figure out how to do helmet.bodyAttributes...
}))