Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(renderer): omitting internal symbol from mdx props #10813

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-mice-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Omitting compiler-internal symbol from user components to fix breaking error messages
2 changes: 2 additions & 0 deletions packages/astro/src/runtime/server/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import mdx from '@astrojs/mdx';
import react from '@astrojs/react';

export default {
integrations: [mdx(), react()],
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useState } from "react";

export default function BrokenComponent() {
useState(0);
a;

return <p>Whoops!</p>;
};
Original file line number Diff line number Diff line change
@@ -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, };
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import BrokenComponent from '../../components/BrokenComponent'

<BrokenComponent {...props} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
import { getCollection } from "astro:content";
const files = await getCollection("files");

const { Content } = await files[0].render();
---

<Content />

33 changes: 33 additions & 0 deletions packages/integrations/mdx/test/mdx-plus-react-errors.test.js
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading