Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path.join(__dirname, '../node_modules/preact/dist/preact.js')
)}
// require reshapePreact
${fs.readFileSync(path.join(__dirname, '../lib/browser.js'))}
// our custom component
${component}
// implementation
var el = document.querySelector('p')
window.out = reshapePreact.hydrateInitialState(el.getAttribute('data-state'), {
'my-component': MyComponent
})
`,
{ runScripts: 'dangerously' }
)
t.is(render(dom.window.out), '<p>the value of foo is "bar"</p>')
})
})
<title>Preact Hacker News</title>
${supportsManifest ? '' : ''}
<style>${resources.inline}</style>
${resources.inline === null && resources.css !== null
? ''
: ''}
${supportsManifest ? '' : ''}
<div id="mount">`);
const RoutedViewComponent: string = render();
res.write(`
${RoutedViewComponent}
</div>
`);
// TODO: More research on why these scripts cannot be loaded async.
res.end();
next();
}
node => {
// encode/compress the original html structure
// this can be rehydrated later to reduce client/server duplication
const originalHtml = encode(node)
return parse(render(toVdom(components, node, originalHtml)))
}
)
render(el: ReactElement, context?: any) {
// FIXME - The behavior here is different across different Preact versions.
// Historically this was because preact-render-to-string v4.x did not support
// Preact 10. In future we should unify them. This will be a breaking change
// as it will affect the output for either Preact v8 or Preact v10.
if (isPreact10()) {
const tempContainer = document.createElement('div');
render(el as any, tempContainer);
const html = tempContainer.innerHTML;
render(h('unmount-me', {}), tempContainer);
return html;
} else {
return renderToString(el as any, context);
}
}
col.get().then(snap => {
const restaurants = snap.docs.map(d => ({ id: d.id, ...d.data() }));
const html = render()
const dataHtml = indexHtml.replace('/** window.__data__ = ::DATA:: ;**/',
`window.__data__ = ${JSON.stringify(restaurants)};`);
console.log(dataHtml);
const finalHtml = dataHtml.replace('', html);
res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
res.send(finalHtml);
});
});
this.state = xtend(this.state, state || {})
assert.notEqual(typeof window, 'object', 'choo.mount: window was found. .toString() must be called in Node, use .start() or .mount() if running in the browser')
assert.equal(typeof location, 'string', 'choo.toString: location should be type string')
assert.equal(typeof this.state, 'object', 'choo.toString: state should be type object')
var self = this
this._stores.forEach(function (initStore) {
initStore(self.state)
})
this._matchRoute(location)
var html = this._prerender(this.state)
assert.ok(html, 'choo.toString: no valid value returned for the route ' + location)
assert(!Array.isArray(html), 'choo.toString: return value was an array for the route ' + location)
return typeof html.outerHTML === 'string' ? html.outerHTML : rendertostring(html)
}
<title>Preact Hacker News</title>
${supportsManifest ? '' : ''}
${resources.inline !== null
? `<style>${resources.inline}</style>`
: resources.css !== null ? `` : ''}
${supportsManifest ? '' : ''}
${resources.route && resources.route.js ? `` : ''}
`);
const RoutedViewComponent: string = render(
,
);
res.write(`
${RoutedViewComponent}
`);
res.end();
next();
}
const renderPage = (title, page) => {
return HtmlPage({ title, content: renderStylesToString(render(page)) });
};
async function serverRender(): Promise {
return { html: render() };
}