Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy authored and astrobot-houston committed Mar 18, 2024
1 parent fcece36 commit 4c1edd0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2765,7 +2765,7 @@ export type SSRComponentMetadata = {
export interface SSRResult {
/**
* Whether the page has failed with a non-recoverable error, or the client disconnected.
*/
*/
cancelled: boolean;
styles: Set<SSRElement>;
scripts: Set<SSRElement>;
Expand Down
60 changes: 30 additions & 30 deletions packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,41 @@ export class RenderContext {

const lastNext = async () => {
switch (routeData.type) {
case 'endpoint': return renderEndpoint(componentInstance as any, apiContext, serverLike, logger);
case 'redirect': return renderRedirect(this);
case 'endpoint':
return renderEndpoint(componentInstance as any, apiContext, serverLike, logger);
case 'redirect':
return renderRedirect(this);
case 'page': {
const result = await this.createResult(componentInstance!);
let response: Response;
try {
response = await renderPage(
result,
componentInstance?.default as any,
props,
{},
streaming,
routeData
);
} catch (e) {
// 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.
result.cancelled = true;
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;
const result = await this.createResult(componentInstance!);
let response: Response;
try {
response = await renderPage(
result,
componentInstance?.default as any,
props,
{},
streaming,
routeData
);
} catch (e) {
// 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.
result.cancelled = true;
throw e;
}
case 'fallback': {
return (
new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: 'fallback' } })
)
// 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': {
return new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: 'fallback' } });
}
}
};

const response = await callMiddleware(middleware, apiContext, lastNext);
if (response.headers.get(ROUTE_TYPE_HEADER)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/astro/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function renderToReadableStream(
// If the client disconnects,
// we signal to ignore the results of existing renders and avoid kicking off more of them.
result.cancelled = true;
}
},
});
}

Expand Down
14 changes: 6 additions & 8 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,30 +459,28 @@ export async function renderComponent(
slots: any = {}
): Promise<RenderInstance> {
if (isPromise(Component)) {
Component = await Component
.catch(handleCancellation);
Component = await Component.catch(handleCancellation);
}

if (isFragmentComponent(Component)) {
return await renderFragmentComponent(result, slots)
.catch(handleCancellation);
return await renderFragmentComponent(result, slots).catch(handleCancellation);
}

// Ensure directives (`class:list`) are processed
props = normalizeProps(props);

// .html components
if (isHTMLComponent(Component)) {
return await renderHTMLComponent(result, Component, props, slots)
.catch(handleCancellation);
return await renderHTMLComponent(result, Component, props, slots).catch(handleCancellation);
}

if (isAstroComponentFactory(Component)) {
return renderAstroComponent(result, displayName, Component, props, slots);
}

return await renderFrameworkComponent(result, displayName, Component, props, slots)
.catch(handleCancellation);
return await renderFrameworkComponent(result, displayName, Component, props, slots).catch(
handleCancellation
);

function handleCancellation(e: unknown) {
if (result.cancelled) return { render() {} };
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Streaming', () => {
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 () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/multiple-errors');
Expand Down

0 comments on commit 4c1edd0

Please sign in to comment.