No HMR support and cached content being served for MDX files with imported components
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- nextjs, typescript
Direzione di ricerca
Riproduci il problema nel contentlayer-mdx-example collegato con yarn dev, modificando src/components/ExampleComponent.tsx e posts/mdx-component-example.mdx; controlla anche il caso ES5 in tsconfig.json e gli errori segnalati in Button.tsx. Il lavoro è completato quando le modifiche ai componenti importati attivano HMR, il riavvio non serve MDX compilato obsoleto e l’esempio documentato funziona con il target TypeScript previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Put together an example here: https://github.com/Saeris/contentlayer-mdx-example
Two things I've observed when trying to import and use components within MDX documents:
- When an imported component has changes, those changes go undetected, meaning HMR is broken for specifically those components. In the linked example, if you run
yarn devthen go tosrc/components/ExampleComponent.tsxand uncomment line 18, this should cause a reload because the component has been changed. I used inline styles here to make it easy to inspect the HTML to confirm the embedded component doesn't update. - Even after restarting the server, Contentlayer is unable to detect that
posts/mdx-component-example.mdxhas any changes (technically this is true, the content of this file is unchanged), so it serves the previously compiled version from the cache. You have to manually purge the cache and generated files in order for any changes to imported components to be reflected in the app.
Effectively this makes authoring mdx content quite a chore and is far from intuitive.
Additionally, if you want to import components that themselves have dependencies (in ExampleComponent, I'm importing Button), you can't set "target": "es5", inside of tsconfig.json such as in the official nextjs example, as you'll get a compilation error:
X [ERROR] Transforming const to the configured target environment ("es5") is not supported yet
../components/Button.tsx:4:7:
4 │ export const Button: FC<{
╵ ~~~~~
The target environment was set to "es5" here:
../tsconfig.json:3:14:
3 │ "target": "es5",
╵ ~~~~~
X [ERROR] Transforming destructuring to the configured target environment ("es5") is not supported yet
../components/Button.tsx:7:6:
7 │ }> = ({ children, onClick }) => (
╵ ^
The target environment was set to "es5" here:
../tsconfig.json:3:14:
3 │ "target": "es5",
╵ ~~~~~
Error: Found 1 problems in 1 documents.
└── Encountered unexpected errors while processing of 1 documents. This is possibly a bug in Contentlayer. Please open an issue.
• "mdx-component-example.mdx": UnexpectedMDXError: Error: Build failed with 2 errors:
../src/components/Button.tsx:4:7: ERROR: Transforming const to the configured target environment ("es5") is not supported yet
../src/components/Button.tsx:7:6: ERROR: Transforming destructuring to the configured target environment ("es5") is not supported yet
SourceFetchDataError: {
"_tag": "HandledFetchDataError"
}
It would be very helpful if there was an official example of how to use custom components in MDX with Contentlayer. Right now there is little if anything to go off of in the documentation.
- Lingua principale
- TypeScript
- Stelle
- 3.5k
- Fork
- 192
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di contentlayerdev/contentlayer
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
contentlayerdev/contentlayer#506 · 84 commenti · 47 reazioni ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path Apertahelp wanted meta: never-stale needs-research
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
contentlayerdev/contentlayer#464 · 4 commenti · 9 reazioni ·
-
State of the project Apertameta: never-stale
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
contentlayerdev/contentlayer#429 · 49 commenti · 83 reazioni ·
-
meta: never-stale topic: markdown/mdx
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
contentlayerdev/contentlayer#421 · 4 reazioni ·
-
meta: never-stale needs-research topic: schema
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
contentlayerdev/contentlayer#420 ·
Tutte le issue di contentlayerdev/contentlayer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
modelcontextprotocol/inspector#2458 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
carbon-design-system/ibm-products#9907 ·