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

[Bug]: 【plugin-playground】Cannot read properties of undefined (reading 'availablePresets') #876

Closed
zmen opened this issue Mar 28, 2024 · 4 comments · Fixed by #898
Closed
Labels
🐞 bug Something isn't working 👏 PR welcome

Comments

@zmen
Copy link

zmen commented Mar 28, 2024

版本信息

System:
    OS: macOS 14.1.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 145.03 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 123.0.6312.86
    Edge: 123.0.2420.65
    Safari: 17.1

问题详情

使用 playground 插件预览组件时经常出现这个报错
cc4156a5-9354-4e2d-b27b-d776e6106d74

复现步骤

  • 创建一个项目,并引入且启用 playground 插件
  • 在 index.mdx 中,随便写一个组件
  • 如果 monaco 的 loader.js 文件先于 babel.min.js 加载完成,就会出现上述报错

由于 babel 脚本体积远大于 monaco 的 loader,所以出现的概率还是挺大的。

@zmen zmen added the 🐞 bug Something isn't working label Mar 28, 2024
@zmen
Copy link
Author

zmen commented Mar 28, 2024

目前定位到的原因:
getBabel 这个方法依赖于 babel.min.js 脚本的加载,在加载完成后读取 window.Babel 变量
28a7c076-d24b-421a-9c40-7fb490a0315f
babel.min.js 中则会判断当前环境是否为浏览器环境,如果是的话就会在 window 上挂载 Babel 变量:
ffad95a1-5fd7-4414-8e13-cf360b650f24
而以 amd 方式加载的 monaco editor 会往 window 上定义 define 变量:
7362f743-9794-4dd4-bc91-cff2727caf5b
因此如果 monaco 先加载完成,babel 会误判当前环境,从而不会正确挂载 window.Babel,因此 rspress 在读取 babel.availablePresets 时报错

@Timeless0911 Timeless0911 changed the title [Bug]: 【@edenx/doc-plugin-playground】Cannot read properties of undefined (reading 'availablePresets') [Bug]: 【plugin-playground】Cannot read properties of undefined (reading 'availablePresets') Mar 29, 2024
@Timeless0911
Copy link
Contributor

Hi, do not expose internal information and sensitive words on the public network. You can use internal oncall service to report the issue~ I have edited the relevant sensitive information in your issue.

@Timeless0911
Copy link
Contributor

Timeless0911 commented Mar 29, 2024

https://github.com/web-infra-dev/rspress/blob/main/packages/plugin-playground/src/cli/index.ts#L216 the logic about the monaco and babel script is in this file.

@zmen I see you have some preliminary conclusions, can you try to make a PR to solve this issue?

@SoonIter
Copy link
Member

SoonIter commented Apr 2, 2024

感谢你的排查和贡献,我个人认为这个错误对于开发体验的影响还是比较大的,尽快修复比较好,我提交了一个 #898 用于修复这个错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 👏 PR welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants