Skip to content

Commit

Permalink
Fix component rerenders if there's only one renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
elite174 committed Oct 6, 2024
1 parent af8401e commit 993f55b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,29 @@ async function renderFrameworkComponent(
}

if (!renderer) {
let error;
for (const r of renderers) {
try {
if (await r.ssr.check.call({ result }, Component, props, children)) {
renderer = r;
break;
// If there's only one renderer in the project
// we can skip the `check` calls and use that renderer
if (Object.keys(renderers).length === 1) {
renderer = renderers[0];
} else {
let error;

for (const r of renderers) {
try {
if (await r.ssr.check.call({ result }, Component, props, children)) {
renderer = r;
break;
}
} catch (e) {
error ??= e;
}
} catch (e) {
error ??= e;
}
}

// If no renderer is found and there is an error, throw that error because
// it is likely a problem with the component code.
if (!renderer && error) {
throw error;
// If no renderer is found and there is an error, throw that error because
// it is likely a problem with the component code.
if (!renderer && error) {
throw error;
}
}
}

Expand Down

0 comments on commit 993f55b

Please sign in to comment.