[ci] format

This commit is contained in:
matthewp 2022-04-21 16:11:09 +00:00 committed by github-actions[bot]
parent ae9ac5cbdc
commit 8768f23f95
5 changed files with 30 additions and 29 deletions

View file

@ -26,7 +26,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
vite.resolve = vite.resolve || {}; vite.resolve = vite.resolve || {};
vite.resolve.alias = vite.resolve.alias || {}; vite.resolve.alias = vite.resolve.alias || {};
const alias = vite.resolve.alias as Record<string, string>; const alias = vite.resolve.alias as Record<string, string>;
alias['react-dom/server'] = 'react-dom/server.browser' alias['react-dom/server'] = 'react-dom/server.browser';
vite.ssr = { vite.ssr = {
noExternal: true, noExternal: true,
}; };

View file

@ -14,7 +14,7 @@ Deno.test({
const html = await resp.text(); const html = await resp.text();
assert(html); assert(html);
const doc = new DOMParser().parseFromString(html, `text/html`); const doc = new DOMParser().parseFromString(html, `text/html`);
const div = doc.querySelector("#react"); const div = doc.querySelector('#react');
assert(div, 'div exists'); assert(div, 'div exists');
}); });
}, },

View file

@ -89,7 +89,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
vite.resolve = vite.resolve || {}; vite.resolve = vite.resolve || {};
vite.resolve.alias = vite.resolve.alias || {}; vite.resolve.alias = vite.resolve.alias || {};
const alias = vite.resolve.alias as Record<string, string>; const alias = vite.resolve.alias as Record<string, string>;
alias['react-dom/server'] = 'react-dom/server.browser' alias['react-dom/server'] = 'react-dom/server.browser';
vite.ssr = { vite.ssr = {
noExternal: true, noExternal: true,
}; };

View file

@ -8,9 +8,7 @@ Deno.test({
name: 'Edge Basics', name: 'Edge Basics',
async fn() { async fn() {
let close = await runBuild('./fixtures/edge-basic/'); let close = await runBuild('./fixtures/edge-basic/');
const { default: handler } = await import( const { default: handler } = await import('./fixtures/edge-basic/dist/edge-functions/entry.js');
'./fixtures/edge-basic/dist/edge-functions/entry.js'
);
const response = await handler(new Request('http://example.com/')); const response = await handler(new Request('http://example.com/'));
assertEquals(response.status, 200); assertEquals(response.status, 200);
const html = await response.text(); const html = await response.text();

View file

@ -65,18 +65,17 @@ async function renderToStaticMarkup(Component, props, children, metadata) {
let html; let html;
if (metadata && metadata.hydrate) { if (metadata && metadata.hydrate) {
html = ReactDOM.renderToString(vnode); html = ReactDOM.renderToString(vnode);
if('renderToReadableStream' in ReactDOM) { if ('renderToReadableStream' in ReactDOM) {
html = await renderToReadableStreamAsync(vnode); html = await renderToReadableStreamAsync(vnode);
} else { } else {
html = await renderToPipeableStreamAsync(vnode); html = await renderToPipeableStreamAsync(vnode);
} }
} else { } else {
if('renderToReadableStream' in ReactDOM) { if ('renderToReadableStream' in ReactDOM) {
html = await renderToReadableStreamAsync(vnode); html = await renderToReadableStreamAsync(vnode);
} else { } else {
html = await renderToStaticNodeStreamAsync(vnode); html = await renderToStaticNodeStreamAsync(vnode);
} }
} }
return { html }; return { html };
} }
@ -92,16 +91,18 @@ async function renderToPipeableStreamAsync(vnode) {
reject(error); reject(error);
}, },
onAllReady() { onAllReady() {
stream.pipe(new Writable({ stream.pipe(
write(chunk, _encoding, callback) { new Writable({
html += chunk.toString('utf-8'); write(chunk, _encoding, callback) {
callback(); html += chunk.toString('utf-8');
}, callback();
destroy() { },
resolve(html); destroy() {
} resolve(html);
})); },
} })
);
},
}); });
}); });
} }
@ -111,15 +112,17 @@ async function renderToStaticNodeStreamAsync(vnode) {
let html = ''; let html = '';
return new Promise((resolve) => { return new Promise((resolve) => {
let stream = ReactDOM.renderToStaticNodeStream(vnode); let stream = ReactDOM.renderToStaticNodeStream(vnode);
stream.pipe(new Writable({ stream.pipe(
write(chunk, _encoding, callback) { new Writable({
html += chunk.toString('utf-8'); write(chunk, _encoding, callback) {
callback(); html += chunk.toString('utf-8');
}, callback();
destroy() { },
resolve(html); destroy() {
} resolve(html);
})); },
})
);
}); });
} }
@ -127,7 +130,7 @@ async function renderToReadableStreamAsync(vnode) {
const decoder = new TextDecoder(); const decoder = new TextDecoder();
const stream = await ReactDOM.renderToReadableStream(vnode); const stream = await ReactDOM.renderToReadableStream(vnode);
let html = ''; let html = '';
for await(const chunk of stream) { for await (const chunk of stream) {
html += decoder.decode(chunk); html += decoder.decode(chunk);
} }
return html; return html;