mirror of
https://github.com/withastro/astro.git
synced 2025-03-17 23:11:29 -05:00
fix(renderer): omitting internal symbol from mdx props (#10813)
This commit is contained in:
parent
fcd19fb8e2
commit
3cc3e2ccba
10 changed files with 108 additions and 0 deletions
5
.changeset/wild-mice-battle.md
Normal file
5
.changeset/wild-mice-battle.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/mdx": patch
|
||||
---
|
||||
|
||||
Omitting compiler-internal symbol from user components to fix breaking error messages
|
|
@ -84,6 +84,8 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|||
}
|
||||
if (typeof vnode.type === 'function') {
|
||||
if (vnode.props[hasTriedRenderComponentSymbol]) {
|
||||
// omitting compiler-internals from user components
|
||||
delete vnode.props[hasTriedRenderComponentSymbol];
|
||||
const output = await vnode.type(vnode.props ?? {});
|
||||
if (output?.[AstroJSX] || !output) {
|
||||
return await renderJSXVNode(result, output);
|
||||
|
|
6
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/astro.config.mjs
vendored
Normal file
6
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import mdx from '@astrojs/mdx';
|
||||
import react from '@astrojs/react';
|
||||
|
||||
export default {
|
||||
integrations: [mdx(), react()],
|
||||
}
|
11
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/package.json
vendored
Normal file
11
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/package.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "@test/mdx-plus-react-errors",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/mdx": "workspace:*",
|
||||
"@astrojs/react": "workspace:*",
|
||||
"astro": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import { useState } from "react";
|
||||
|
||||
export default function BrokenComponent() {
|
||||
useState(0);
|
||||
a;
|
||||
|
||||
return <p>Whoops!</p>;
|
||||
};
|
12
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/content/config.js
vendored
Normal file
12
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/content/config.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { z, defineCollection } from "astro:content";
|
||||
|
||||
const filesSchema = () => {
|
||||
return z.object({});
|
||||
};
|
||||
|
||||
const filesCollection = defineCollection({
|
||||
type: "content",
|
||||
schema: filesSchema(),
|
||||
});
|
||||
|
||||
export const collections = { files: filesCollection, };
|
4
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/content/files/file.mdx
vendored
Normal file
4
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/content/files/file.mdx
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
import BrokenComponent from '../../components/BrokenComponent'
|
||||
|
||||
<BrokenComponent {...props} />
|
9
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/pages/broken.astro
vendored
Normal file
9
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors/src/pages/broken.astro
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
import { getCollection } from "astro:content";
|
||||
const files = await getCollection("files");
|
||||
|
||||
const { Content } = await files[0].render();
|
||||
---
|
||||
|
||||
<Content />
|
||||
|
33
packages/integrations/mdx/test/mdx-plus-react-errors.test.js
Normal file
33
packages/integrations/mdx/test/mdx-plus-react-errors.test.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import * as assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { loadFixture } from '../../../astro/test/test-utils.js';
|
||||
|
||||
function hookError() {
|
||||
const error = console.error;
|
||||
const errors = [];
|
||||
console.error = function (...args) {
|
||||
errors.push(args);
|
||||
};
|
||||
return () => {
|
||||
console.error = error;
|
||||
return errors;
|
||||
};
|
||||
}
|
||||
|
||||
describe('MDX and React with build errors', () => {
|
||||
let fixture;
|
||||
let unhook;
|
||||
|
||||
it('shows correct error messages on build error', async () => {
|
||||
try {
|
||||
fixture = await loadFixture({
|
||||
root: new URL('./fixtures/mdx-plus-react-errors/', import.meta.url),
|
||||
});
|
||||
unhook = hookError();
|
||||
await fixture.build();
|
||||
} catch (err) {
|
||||
assert.equal(err.message, 'a is not defined');
|
||||
}
|
||||
unhook();
|
||||
});
|
||||
});
|
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
|
@ -4679,6 +4679,24 @@ importers:
|
|||
specifier: ^18.3.1
|
||||
version: 18.3.1(react@18.3.1)
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-plus-react-errors:
|
||||
dependencies:
|
||||
'@astrojs/mdx':
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
'@astrojs/react':
|
||||
specifier: workspace:*
|
||||
version: link:../../../../react
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
react:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1
|
||||
react-dom:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1(react@18.3.1)
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-vite-env-vars:
|
||||
dependencies:
|
||||
'@astrojs/mdx':
|
||||
|
|
Loading…
Add table
Reference in a new issue