diff --git a/.changeset/lazy-cameras-float.md b/.changeset/lazy-cameras-float.md new file mode 100644 index 000000000..4e680c003 --- /dev/null +++ b/.changeset/lazy-cameras-float.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes use of multiple renderers when one throws diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index ebec0487a..9a655d380 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -310,7 +310,9 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`') } } - if (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; } } diff --git a/packages/astro/test/fixtures/multiple-renderers/astro.config.mjs b/packages/astro/test/fixtures/multiple-renderers/astro.config.mjs new file mode 100644 index 000000000..526323dbf --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/astro.config.mjs @@ -0,0 +1,6 @@ +import one from '@astrojs/renderer-one'; +import two from '@astrojs/renderer-two'; + +export default { + integrations: [one(), two()] +}; diff --git a/packages/astro/test/fixtures/multiple-renderers/package.json b/packages/astro/test/fixtures/multiple-renderers/package.json new file mode 100644 index 000000000..9372a6e94 --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/multiple-renderers", + "dependencies": { + "astro": "workspace:*", + "@astrojs/renderer-one": "file:./renderers/one", + "@astrojs/renderer-two": "file:./renderers/two" + } +} diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/one/index.mjs b/packages/astro/test/fixtures/multiple-renderers/renderers/one/index.mjs new file mode 100644 index 000000000..3e39696bf --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/one/index.mjs @@ -0,0 +1,15 @@ + +export default function() { + return { + name: 'renderer-one', + hooks: { + 'astro:config:setup': ({ addRenderer }) => { + addRenderer({ + name: 'renderer-one', + clientEntrypoint: null, + serverEntrypoint: '@astrojs/renderer-one/server.mjs', + }); + } + } + }; +} diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/one/package.json b/packages/astro/test/fixtures/multiple-renderers/renderers/one/package.json new file mode 100644 index 000000000..30a2cf6de --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/one/package.json @@ -0,0 +1,5 @@ +{ + "name": "@astrojs/renderer-one", + "version": "1.0.0", + "main": "index.mjs" +} diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/one/server.mjs b/packages/astro/test/fixtures/multiple-renderers/renderers/one/server.mjs new file mode 100644 index 000000000..52db653fa --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/one/server.mjs @@ -0,0 +1,11 @@ + +export default { + check() { + throw new Error(`Oops this did not work`); + }, + renderToStaticMarkup(Component) { + return { + html: Component() + }; + }, +}; diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/two/index.mjs b/packages/astro/test/fixtures/multiple-renderers/renderers/two/index.mjs new file mode 100644 index 000000000..729356d24 --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/two/index.mjs @@ -0,0 +1,15 @@ + +export default function() { + return { + name: 'renderer-two', + hooks: { + 'astro:config:setup': ({ addRenderer }) => { + addRenderer({ + name: 'renderer-two', + clientEntrypoint: null, + serverEntrypoint: '@astrojs/renderer-two/server.mjs', + }); + } + } + }; +} diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/two/package.json b/packages/astro/test/fixtures/multiple-renderers/renderers/two/package.json new file mode 100644 index 000000000..51216ac57 --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/two/package.json @@ -0,0 +1,5 @@ +{ + "name": "@astrojs/renderer-two", + "version": "1.0.0", + "main": "index.mjs" +} diff --git a/packages/astro/test/fixtures/multiple-renderers/renderers/two/server.mjs b/packages/astro/test/fixtures/multiple-renderers/renderers/two/server.mjs new file mode 100644 index 000000000..cba48ac24 --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/renderers/two/server.mjs @@ -0,0 +1,11 @@ + +export default { + check() { + return true; + }, + renderToStaticMarkup(Component) { + return { + html: Component() + }; + }, +}; diff --git a/packages/astro/test/fixtures/multiple-renderers/src/pages/index.astro b/packages/astro/test/fixtures/multiple-renderers/src/pages/index.astro new file mode 100644 index 000000000..1708d1cc9 --- /dev/null +++ b/packages/astro/test/fixtures/multiple-renderers/src/pages/index.astro @@ -0,0 +1,14 @@ +--- + function Component() { + return `