No HMR support and cached content being served for MDX files with imported components
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- nextjs, typescript
调研方向
使用 yarn dev 在链接的 contentlayer-mdx-example 中重现该问题,修改 src/components/ExampleComponent.tsx 和 posts/mdx-component-example.mdx;同时检查 tsconfig.json 中的 ES5 情况以及 Button.tsx 中报告的错误。当导入组件的更改会触发 HMR、重启不会提供过时的已编译 MDX,并且文档中的示例能在预期的 TypeScript 目标下正常工作时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 3.5k
- 派生
- 192
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
contentlayerdev/contentlayer 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 25/100
contentlayerdev/contentlayer#506 · 84 条评论 · 47 个 reaction ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path 未关闭help wanted meta: never-stale needs-research
难度 4/5 3-5 天 新手友好度 38/100
contentlayerdev/contentlayer#464 · 4 条评论 · 9 个 reaction ·
-
meta: never-stale
难度 5/5 一周以上 新手友好度 10/100
contentlayerdev/contentlayer#429 · 49 条评论 · 83 个 reaction ·
-
meta: never-stale topic: markdown/mdx
难度 4/5 3-5 天 新手友好度 42/100
contentlayerdev/contentlayer#421 · 4 个 reaction ·
-
meta: never-stale needs-research topic: schema
难度 5/5 一周以上 新手友好度 25/100
contentlayerdev/contentlayer#420 ·
查看 contentlayerdev/contentlayer 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 1/5 1 小时以内 新手友好度 90/100
TanStack/tanstack.com#1293 ·