Skip to content

Commit 8c9cc4c

Browse files
committed
fix(mdx): better error when missing component
1 parent 2a41ab7 commit 8c9cc4c

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

packages/docs/src/routes/api/qwik/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@
25722572
}
25732573
],
25742574
"kind": "Variable",
2575-
"content": "Allows to project the children of the current component. <Slot/> can only be used within the context of a component defined with `component$`<!-- -->.\n\n\n```typescript\nSlot: FunctionComponent<{\n name?: string;\n}>\n```",
2575+
"content": "Allows to project the children of the current component. `<Slot/>` can only be used within the context of a component defined with `component$`<!-- -->.\n\n\n```typescript\nSlot: FunctionComponent<{\n name?: string;\n}>\n```",
25762576
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/render/jsx/slot.public.ts",
25772577
"mdFile": "qwik.slot.md"
25782578
},

packages/docs/src/routes/api/qwik/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,7 @@ SkipRender: JSXNode;
53635363
53645364
## Slot
53655365
5366-
Allows to project the children of the current component. <Slot/> can only be used within the context of a component defined with `component$`.
5366+
Allows to project the children of the current component. `<Slot/>` can only be used within the context of a component defined with `component$`.
53675367
53685368
```typescript
53695369
Slot: FunctionComponent<{

packages/qwik-city/src/buildtime/markdown/mdx.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export async function createMdxTransformer(ctx: BuildContext): Promise<MdxTransf
7878
.replace('+', '-')
7979
.replace('/', '_');
8080
const addImport = `import { jsx, _jsxC, RenderOnce } from '@builder.io/qwik';\n`;
81-
const newDefault = `
81+
// the _missingMdxReference call is automatically added by mdxjs
82+
const newDefault = `
83+
function _missingMdxReference(id, component, place) {
84+
throw new Error("${id}: Expected " + (component ? "component" : "object") + " \`" + id + "\` to be defined: you likely forgot to import, pass, or provide it." + (place ? "\\nIt’s referenced in your code at \`" + place + "\`" : ""));
85+
}
8286
const WrappedMdxContent = (props = {}) => {
8387
const content = _jsxC(RenderOnce, {children: _jsxC(_createMdxContent, props, 3, null)}, 3, ${JSON.stringify(key)});
8488
if (typeof MDXLayout === 'function'){

packages/qwik-city/src/buildtime/markdown/mdx.unit.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ describe('mdx', async () => {
6060
})]
6161
});
6262
}
63-
63+
64+
function _missingMdxReference(id, component, place) {
65+
throw new Error("file.mdx: Expected " + (component ? "component" : "object") + " \`" + id + "\` to be defined: you likely forgot to import, pass, or provide it." + (place ? "\\nIt’s referenced in your code at \`" + place + "\`" : ""));
66+
}
6467
const WrappedMdxContent = (props = {}) => {
6568
const content = _jsxC(RenderOnce, {children: _jsxC(_createMdxContent, props, 3, null)}, 3, "eB2HIyA1");
6669
if (typeof MDXLayout === 'function'){
@@ -137,7 +140,10 @@ export default function Layout({ children: content }) {
137140
})]
138141
});
139142
}
140-
143+
144+
function _missingMdxReference(id, component, place) {
145+
throw new Error("file.mdx: Expected " + (component ? "component" : "object") + " \`" + id + "\` to be defined: you likely forgot to import, pass, or provide it." + (place ? "\\nIt’s referenced in your code at \`" + place + "\`" : ""));
146+
}
141147
const WrappedMdxContent = (props = {}) => {
142148
const content = _jsxC(RenderOnce, {children: _jsxC(_createMdxContent, props, 3, null)}, 3, "UdQmQWC3");
143149
if (typeof MDXLayout === 'function'){

packages/qwik/src/core/render/jsx/slot.public.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Virtual, _jsxC } from './jsx-runtime';
33
import type { FunctionComponent } from './types/jsx-node';
44

55
/**
6-
* Allows to project the children of the current component. <Slot/> can only be used within the
6+
* Allows to project the children of the current component. `<Slot/>` can only be used within the
77
* context of a component defined with `component$`.
88
*
99
* @public

0 commit comments

Comments
 (0)