Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectError
extractCritical(renderedString, undefined as any)
// $ExpectType string
renderStylesToString(renderedString)
// $ExpectError
renderStylesToString()
// $ExpectError
renderStylesToString(renderedString, undefined as any)
// $ExpectType ReadWriteStream
renderStylesToNodeStream()
// $ExpectError
renderStylesToNodeStream(undefined as any)
renderedNodeStream.pipe(renderStylesToNodeStream())
renderToMedium(gmctx, element) {
element = super.renderToMedium(gmctx, element);
if (element) {
if (typeof element === "string") {
return renderStylesToString(element);
} else {
const output = renderStylesToNodeStream();
return pump(element, output, err => {
// `pump` doesn't forward the error from source to output stream
// (perhaps) per Node's default behavior. It just silently destroys
// the output stream to make sure no leak occurs.
if (err)
output.destroy(err);
});
}
} else {
return element;
}
}
};
const renderStreamed = async (ctx, path, clientStats, outputPath) => {
// Grab the CSS from our sheetsRegistry.
clearChunks();
const store = await configureStore(ctx);
if (!store) return; // no store means redirect was already served
const stateJson = JSON.stringify(store.getState());
const {css} = flushChunks(clientStats, {outputPath});
const chunkNames = [];
const app = createApp(App, store, chunkNames);
const stream = renderToNodeStream(app).pipe(renderStylesToNodeStream());
// flush the head with css & js resource tags first so the download starts immediately
const early = earlyChunk(css, stateJson);
// DO not use redis cache on dev
let mainStream;
if (process.env.NODE_ENV === 'development') {
mainStream = ctx.body;
}
else {
mainStream = createCacheStream(path);
mainStream.pipe(ctx.body);
}
mainStream.write(early);
async renderToNodeStream({ res, render, component }) {
const delemitter = ``;
const content = await render(delemitter);
const [before, after] = content.split(delemitter);
res.write(before);
const stream = renderToNodeStream(component).pipe(renderStylesToNodeStream());
stream.pipe(res, { end: false });
stream.on('end', () => {
res.write(after);
res.end();
});
}
console.log(e);
}
const state = client.cache.extract();
const [header, footer] = template({
helmet: res.locals.helmetContext.helmet,
stylesheets,
state,
assets,
});
res.status(200);
res.write(header);
renderToNodeStream(app)
.pipe(renderStylesToNodeStream())
.pipe(
through(
function write(data) {
this.queue(data);
},
function end() {
this.queue(footer);
this.queue(null);
}
)
)
.pipe(res);
};
return new Promise(resolve => {
let html = "";
const stream = renderToStaticNodeStream(ui).pipe(
renderStylesToNodeStream()
);
stream.on("data", chunk => {
html += chunk;
});
stream.on("end", () => {
resolve(html);
});
});
}
return new Promise(resolve => {
let html = "";
const stream = renderToStaticNodeStream(ui).pipe(
renderStylesToNodeStream()
);
stream.on("data", chunk => {
html += chunk;
});
stream.on("end", () => {
resolve(html);
});
});
}
const device = devices[req.device.type]
const props = {
scripts: clientStats[device]
.chunks
.filter(chunk => chunk.initial)
.reduce((files, chunk) => files.concat(`${clientStats[device].publicPath}${chunk.files[0]}`), []),
}
res.status(200)
res.contentType('text/html; charset=utf-8')
res.write('')
const Server = servers[req.device.type]
const stream = renderToNodeStream().pipe(renderStylesToNodeStream())
stream.pipe(res, {end: false})
stream.on('end', () => res.end())
}
}
<div id="root">`
);
const stream = renderToNodeStream(
as any
);
stream.pipe(renderStylesToNodeStream());
stream.pipe(res, { end: false });
return stream.on('end', () => {
res.write(`</div>
${
process.env.NODE_ENV === 'production'
? ``
: ``
}
`);
return res.end();
});
});
};