Only rethrow renderer error when no renderer found (#4131)
* Only rethrow renderer error when no renderer found * Adds a changeset
This commit is contained in:
parent
acd0b6da3c
commit
09eca9be5e
13 changed files with 147 additions and 1 deletions
5
.changeset/lazy-cameras-float.md
Normal file
5
.changeset/lazy-cameras-float.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes use of multiple renderers when one throws
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
6
packages/astro/test/fixtures/multiple-renderers/astro.config.mjs
vendored
Normal file
6
packages/astro/test/fixtures/multiple-renderers/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import one from '@astrojs/renderer-one';
|
||||
import two from '@astrojs/renderer-two';
|
||||
|
||||
export default {
|
||||
integrations: [one(), two()]
|
||||
};
|
8
packages/astro/test/fixtures/multiple-renderers/package.json
vendored
Normal file
8
packages/astro/test/fixtures/multiple-renderers/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@test/multiple-renderers",
|
||||
"dependencies": {
|
||||
"astro": "workspace:*",
|
||||
"@astrojs/renderer-one": "file:./renderers/one",
|
||||
"@astrojs/renderer-two": "file:./renderers/two"
|
||||
}
|
||||
}
|
15
packages/astro/test/fixtures/multiple-renderers/renderers/one/index.mjs
vendored
Normal file
15
packages/astro/test/fixtures/multiple-renderers/renderers/one/index.mjs
vendored
Normal file
|
@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
5
packages/astro/test/fixtures/multiple-renderers/renderers/one/package.json
vendored
Normal file
5
packages/astro/test/fixtures/multiple-renderers/renderers/one/package.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@astrojs/renderer-one",
|
||||
"version": "1.0.0",
|
||||
"main": "index.mjs"
|
||||
}
|
11
packages/astro/test/fixtures/multiple-renderers/renderers/one/server.mjs
vendored
Normal file
11
packages/astro/test/fixtures/multiple-renderers/renderers/one/server.mjs
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
export default {
|
||||
check() {
|
||||
throw new Error(`Oops this did not work`);
|
||||
},
|
||||
renderToStaticMarkup(Component) {
|
||||
return {
|
||||
html: Component()
|
||||
};
|
||||
},
|
||||
};
|
15
packages/astro/test/fixtures/multiple-renderers/renderers/two/index.mjs
vendored
Normal file
15
packages/astro/test/fixtures/multiple-renderers/renderers/two/index.mjs
vendored
Normal file
|
@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
5
packages/astro/test/fixtures/multiple-renderers/renderers/two/package.json
vendored
Normal file
5
packages/astro/test/fixtures/multiple-renderers/renderers/two/package.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@astrojs/renderer-two",
|
||||
"version": "1.0.0",
|
||||
"main": "index.mjs"
|
||||
}
|
11
packages/astro/test/fixtures/multiple-renderers/renderers/two/server.mjs
vendored
Normal file
11
packages/astro/test/fixtures/multiple-renderers/renderers/two/server.mjs
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
export default {
|
||||
check() {
|
||||
return true;
|
||||
},
|
||||
renderToStaticMarkup(Component) {
|
||||
return {
|
||||
html: Component()
|
||||
};
|
||||
},
|
||||
};
|
14
packages/astro/test/fixtures/multiple-renderers/src/pages/index.astro
vendored
Normal file
14
packages/astro/test/fixtures/multiple-renderers/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
function Component() {
|
||||
return `<div id="component">works</div>`;
|
||||
}
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testing</h1>
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
21
packages/astro/test/multiple-renderers.test.js
Normal file
21
packages/astro/test/multiple-renderers.test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Multiple renderers', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/multiple-renderers/',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('when the first throws but the second does not, use the second renderer', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
expect($('#component')).to.have.a.lengthOf(1);
|
||||
});
|
||||
});
|
|
@ -1634,6 +1634,22 @@ importers:
|
|||
'@astrojs/preact': link:../../../../integrations/preact
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/multiple-renderers:
|
||||
specifiers:
|
||||
'@astrojs/renderer-one': file:./renderers/one
|
||||
'@astrojs/renderer-two': file:./renderers/two
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/renderer-one': file:packages/astro/test/fixtures/multiple-renderers/renderers/one
|
||||
'@astrojs/renderer-two': file:packages/astro/test/fixtures/multiple-renderers/renderers/two
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/multiple-renderers/renderers/one:
|
||||
specifiers: {}
|
||||
|
||||
packages/astro/test/fixtures/multiple-renderers/renderers/two:
|
||||
specifiers: {}
|
||||
|
||||
packages/astro/test/fixtures/page-level-styles:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
|
@ -17079,3 +17095,15 @@ packages:
|
|||
name: '@astrojs/test-font-awesome-package'
|
||||
version: 0.0.1
|
||||
dev: false
|
||||
|
||||
file:packages/astro/test/fixtures/multiple-renderers/renderers/one:
|
||||
resolution: {directory: packages/astro/test/fixtures/multiple-renderers/renderers/one, type: directory}
|
||||
name: '@astrojs/renderer-one'
|
||||
version: 1.0.0
|
||||
dev: false
|
||||
|
||||
file:packages/astro/test/fixtures/multiple-renderers/renderers/two:
|
||||
resolution: {directory: packages/astro/test/fixtures/multiple-renderers/renderers/two, type: directory}
|
||||
name: '@astrojs/renderer-two'
|
||||
version: 1.0.0
|
||||
dev: false
|
||||
|
|
Loading…
Reference in a new issue