Prevent server hang in MDX when code throws
This commit is contained in:
parent
e5c64c51c1
commit
25643a0beb
8 changed files with 72 additions and 0 deletions
|
@ -85,6 +85,7 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|||
}
|
||||
} catch (e) {
|
||||
skipAstroJSXCheck.add(vnode.type);
|
||||
throw e;
|
||||
} finally {
|
||||
finishUsingConsoleFilter();
|
||||
}
|
||||
|
|
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/astro.config.mjs
vendored
Normal file
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import mdx from '@astrojs/mdx';
|
||||
|
||||
export default {
|
||||
integrations: [mdx()]
|
||||
}
|
7
packages/integrations/mdx/test/fixtures/mdx-throw-error/package.json
vendored
Normal file
7
packages/integrations/mdx/test/fixtures/mdx-throw-error/package.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@test/mdx-throw-error",
|
||||
"dependencies": {
|
||||
"@astrojs/mdx": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/components/component.mdx
vendored
Normal file
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/components/component.mdx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { throwError } from '../js/throwerror';
|
||||
|
||||
This will probably result in a stack overflow. :(
|
||||
|
||||
<pre>{ throwError() }</pre>
|
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/js/throwerror.ts
vendored
Normal file
5
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/js/throwerror.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
export function throwError() {
|
||||
console.log(`I'm going to throw an error. The server will just keep spinning until it runs out of memory...`);
|
||||
|
||||
throw new Error('Oh no');
|
||||
}
|
16
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/pages/index.astro
vendored
Normal file
16
packages/integrations/mdx/test/fixtures/mdx-throw-error/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
|
||||
import Component from '../components/component.mdx';
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Astro MDX Errors</h1>
|
||||
|
||||
<Component />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
25
packages/integrations/mdx/test/mdx-throw-errors.test.js
Normal file
25
packages/integrations/mdx/test/mdx-throw-errors.test.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import mdx from '@astrojs/mdx';
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { loadFixture } from '../../../astro/test/test-utils.js';
|
||||
|
||||
describe('MDX errors', () => {
|
||||
/** @type {import('../../../astro/test/test-utils.js').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: new URL('./fixtures/mdx-throw-error/', import.meta.url),
|
||||
integrations: [mdx()],
|
||||
});
|
||||
});
|
||||
|
||||
it('throws error during the build (does not lock up)', async () => {
|
||||
try {
|
||||
await fixture.build();
|
||||
expect(false).to.equal(true);
|
||||
} catch(err) {
|
||||
expect(err.message).to.equal('Oh no');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -2821,6 +2821,14 @@ importers:
|
|||
react: 18.2.0
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-throw-error:
|
||||
specifiers:
|
||||
'@astrojs/mdx': workspace:*
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/mdx': link:../../..
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-vite-env-vars:
|
||||
specifiers:
|
||||
'@astrojs/mdx': workspace:*
|
||||
|
|
Loading…
Reference in a new issue