()
| 36 | document.getElementById('preact_root') || document.body.firstElementChild; |
| 37 | |
| 38 | let init = () => { |
| 39 | let app = interopDefault(require('preact-cli-entrypoint')); |
| 40 | let preRenderData = {}; |
| 41 | const inlineDataElement = document.querySelector( |
| 42 | '[type="__PREACT_CLI_DATA__"]' |
| 43 | ); |
| 44 | if (inlineDataElement) { |
| 45 | preRenderData = |
| 46 | JSON.parse(decodeURI(inlineDataElement.innerHTML)).preRenderData || |
| 47 | preRenderData; |
| 48 | } |
| 49 | /* An object named CLI_DATA is passed as a prop, |
| 50 | * this keeps us future proof if in case we decide, |
| 51 | * to send other data like at some point in time. |
| 52 | */ |
| 53 | const CLI_DATA = { preRenderData }; |
| 54 | const currentURL = preRenderData.url ? normalizeURL(preRenderData.url) : ''; |
| 55 | const canHydrate = |
| 56 | process.env.PRERENDER && |
| 57 | process.env.NODE_ENV === 'production' && |
| 58 | hydrate && |
| 59 | currentURL === normalizeURL(location.pathname); |
| 60 | const doRender = canHydrate ? hydrate : render; |
| 61 | doRender(h(app, { CLI_DATA }), document.body, root); |
| 62 | }; |
| 63 | |
| 64 | if (module.hot) module.hot.accept('preact-cli-entrypoint', init); |
| 65 |
no test coverage detected
searching dependent graphs…