refactor: auto root
This commit is contained in:
parent
0039fb0f59
commit
c001be6647
|
@ -20,14 +20,14 @@ class Ssr extends Transform {
|
||||||
async _transform(chunk, encoding, done) {
|
async _transform(chunk, encoding, done) {
|
||||||
const string = chunk.toString('utf8');
|
const string = chunk.toString('utf8');
|
||||||
const {appMountId} = this.flecks.get('@flecks/web/server');
|
const {appMountId} = this.flecks.get('@flecks/web/server');
|
||||||
if (-1 !== string.indexOf(`<div id="${appMountId}"></div>`)) {
|
if (-1 !== string.indexOf(`<div id="${appMountId}">`)) {
|
||||||
try {
|
try {
|
||||||
const renderedRoot = ReactDOMServer.renderToString(
|
const renderedRoot = ReactDOMServer.renderToString(
|
||||||
React.createElement(await root(this.flecks, this.req)),
|
React.createElement(await root(this.flecks, this.req)),
|
||||||
);
|
);
|
||||||
const rendered = string.replaceAll(
|
const rendered = string.replaceAll(
|
||||||
`<div id="${appMountId}"></div>`,
|
`<div id="${appMountId}">`,
|
||||||
`<div id="${appMountId}">${renderedRoot}</div>`,
|
`<div id="${appMountId}">${renderedRoot}`,
|
||||||
);
|
);
|
||||||
this.push(rendered);
|
this.push(rendered);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ const {version} = require('@flecks/web/package.json');
|
||||||
try {
|
try {
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
await flecks.invokeSequentialAsync('@flecks/web/client.up');
|
await flecks.invokeSequentialAsync('@flecks/web/client.up');
|
||||||
const appMountId = `#${config['@flecks/web/client'].appMountId}`;
|
const appMountContainerId = `#${config['@flecks/web/client'].appMountId}-container`;
|
||||||
window.document.querySelector(appMountId).style.display = 'block';
|
window.document.querySelector(appMountContainerId).style.display = 'block';
|
||||||
debug('up!');
|
debug('up!');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="<%= htmlWebpackPlugin.options.appMountId %>"></div>
|
|
||||||
<%= htmlWebpackPlugin.tags.bodyTags %>
|
<%= htmlWebpackPlugin.tags.bodyTags %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -45,20 +45,18 @@ class InlineConfig extends Transform {
|
||||||
async _transform(chunk, encoding, done) {
|
async _transform(chunk, encoding, done) {
|
||||||
const string = chunk.toString('utf8');
|
const string = chunk.toString('utf8');
|
||||||
const {appMountId} = this.flecks.get('@flecks/web/server');
|
const {appMountId} = this.flecks.get('@flecks/web/server');
|
||||||
if (-1 !== string.indexOf(`<div id="${appMountId}"></div>`)) {
|
const rendered = string.replaceAll(
|
||||||
const rendered = string.replaceAll(
|
'<body>',
|
||||||
|
[
|
||||||
|
'<body>',
|
||||||
|
`<div id="${appMountId}-container">`,
|
||||||
|
`<script>window.document.querySelector('#${appMountId}-container').style.display = 'none'</script>`,
|
||||||
|
`<script>${await configSource(this.flecks, this.req)}</script>`,
|
||||||
`<div id="${appMountId}"></div>`,
|
`<div id="${appMountId}"></div>`,
|
||||||
[
|
'</div>',
|
||||||
`<div id="${appMountId}"></div>`,
|
].join(''),
|
||||||
`<script>window.document.querySelector('#${appMountId}').style.display = 'none'</script>`,
|
);
|
||||||
`<script>${await configSource(this.flecks, this.req)}</script>`,
|
this.push(rendered);
|
||||||
].join(''),
|
|
||||||
);
|
|
||||||
this.push(rendered);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.push(string);
|
|
||||||
}
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user