mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
[ci] format
This commit is contained in:
parent
fcece36586
commit
4c1edd0af5
5 changed files with 39 additions and 41 deletions
|
@ -2765,7 +2765,7 @@ export type SSRComponentMetadata = {
|
||||||
export interface SSRResult {
|
export interface SSRResult {
|
||||||
/**
|
/**
|
||||||
* Whether the page has failed with a non-recoverable error, or the client disconnected.
|
* Whether the page has failed with a non-recoverable error, or the client disconnected.
|
||||||
*/
|
*/
|
||||||
cancelled: boolean;
|
cancelled: boolean;
|
||||||
styles: Set<SSRElement>;
|
styles: Set<SSRElement>;
|
||||||
scripts: Set<SSRElement>;
|
scripts: Set<SSRElement>;
|
||||||
|
|
|
@ -90,41 +90,41 @@ export class RenderContext {
|
||||||
|
|
||||||
const lastNext = async () => {
|
const lastNext = async () => {
|
||||||
switch (routeData.type) {
|
switch (routeData.type) {
|
||||||
case 'endpoint': return renderEndpoint(componentInstance as any, apiContext, serverLike, logger);
|
case 'endpoint':
|
||||||
case 'redirect': return renderRedirect(this);
|
return renderEndpoint(componentInstance as any, apiContext, serverLike, logger);
|
||||||
|
case 'redirect':
|
||||||
|
return renderRedirect(this);
|
||||||
case 'page': {
|
case 'page': {
|
||||||
const result = await this.createResult(componentInstance!);
|
const result = await this.createResult(componentInstance!);
|
||||||
let response: Response;
|
let response: Response;
|
||||||
try {
|
try {
|
||||||
response = await renderPage(
|
response = await renderPage(
|
||||||
result,
|
result,
|
||||||
componentInstance?.default as any,
|
componentInstance?.default as any,
|
||||||
props,
|
props,
|
||||||
{},
|
{},
|
||||||
streaming,
|
streaming,
|
||||||
routeData
|
routeData
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If there is an error in the page's frontmatter or instantiation of the RenderTemplate fails midway,
|
// If there is an error in the page's frontmatter or instantiation of the RenderTemplate fails midway,
|
||||||
// we signal to the rest of the internals that we can ignore the results of existing renders and avoid kicking off more of them.
|
// we signal to the rest of the internals that we can ignore the results of existing renders and avoid kicking off more of them.
|
||||||
result.cancelled = true;
|
result.cancelled = true;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
|
||||||
// Signal to the i18n middleware to maybe act on this response
|
|
||||||
response.headers.set(ROUTE_TYPE_HEADER, 'page');
|
|
||||||
// Signal to the error-page-rerouting infra to let this response pass through to avoid loops
|
|
||||||
if (routeData.route === '/404' || routeData.route === '/500') {
|
|
||||||
response.headers.set(REROUTE_DIRECTIVE_HEADER, 'no');
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
case 'fallback': {
|
// Signal to the i18n middleware to maybe act on this response
|
||||||
return (
|
response.headers.set(ROUTE_TYPE_HEADER, 'page');
|
||||||
new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: 'fallback' } })
|
// Signal to the error-page-rerouting infra to let this response pass through to avoid loops
|
||||||
)
|
if (routeData.route === '/404' || routeData.route === '/500') {
|
||||||
|
response.headers.set(REROUTE_DIRECTIVE_HEADER, 'no');
|
||||||
}
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
case 'fallback': {
|
||||||
|
return new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: 'fallback' } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const response = await callMiddleware(middleware, apiContext, lastNext);
|
const response = await callMiddleware(middleware, apiContext, lastNext);
|
||||||
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
||||||
|
|
|
@ -129,7 +129,7 @@ export async function renderToReadableStream(
|
||||||
// If the client disconnects,
|
// If the client disconnects,
|
||||||
// we signal to ignore the results of existing renders and avoid kicking off more of them.
|
// we signal to ignore the results of existing renders and avoid kicking off more of them.
|
||||||
result.cancelled = true;
|
result.cancelled = true;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -459,13 +459,11 @@ export async function renderComponent(
|
||||||
slots: any = {}
|
slots: any = {}
|
||||||
): Promise<RenderInstance> {
|
): Promise<RenderInstance> {
|
||||||
if (isPromise(Component)) {
|
if (isPromise(Component)) {
|
||||||
Component = await Component
|
Component = await Component.catch(handleCancellation);
|
||||||
.catch(handleCancellation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFragmentComponent(Component)) {
|
if (isFragmentComponent(Component)) {
|
||||||
return await renderFragmentComponent(result, slots)
|
return await renderFragmentComponent(result, slots).catch(handleCancellation);
|
||||||
.catch(handleCancellation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure directives (`class:list`) are processed
|
// Ensure directives (`class:list`) are processed
|
||||||
|
@ -473,16 +471,16 @@ export async function renderComponent(
|
||||||
|
|
||||||
// .html components
|
// .html components
|
||||||
if (isHTMLComponent(Component)) {
|
if (isHTMLComponent(Component)) {
|
||||||
return await renderHTMLComponent(result, Component, props, slots)
|
return await renderHTMLComponent(result, Component, props, slots).catch(handleCancellation);
|
||||||
.catch(handleCancellation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAstroComponentFactory(Component)) {
|
if (isAstroComponentFactory(Component)) {
|
||||||
return renderAstroComponent(result, displayName, Component, props, slots);
|
return renderAstroComponent(result, displayName, Component, props, slots);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await renderFrameworkComponent(result, displayName, Component, props, slots)
|
return await renderFrameworkComponent(result, displayName, Component, props, slots).catch(
|
||||||
.catch(handleCancellation);
|
handleCancellation
|
||||||
|
);
|
||||||
|
|
||||||
function handleCancellation(e: unknown) {
|
function handleCancellation(e: unknown) {
|
||||||
if (result.cancelled) return { render() {} };
|
if (result.cancelled) return { render() {} };
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe('Streaming', () => {
|
||||||
assert.equal(chunks.length > 1, true);
|
assert.equal(chunks.length > 1, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the offshoot promise goes unhandled, this test will pass immediately but fail the test suite
|
// if the offshoot promise goes unhandled, this test will pass immediately but fail the test suite
|
||||||
it('Stays alive on failed component renders initiated by failed render templates', async () => {
|
it('Stays alive on failed component renders initiated by failed render templates', async () => {
|
||||||
const app = await fixture.loadTestAdapterApp();
|
const app = await fixture.loadTestAdapterApp();
|
||||||
const request = new Request('http://example.com/multiple-errors');
|
const request = new Request('http://example.com/multiple-errors');
|
||||||
|
|
Loading…
Add table
Reference in a new issue