-
Notifications
You must be signed in to change notification settings - Fork 65
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
use globalThis instead of window in HMR #134
Conversation
This fixes for more context: https://wintercg.org/
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #134 +/- ##
==========================================
- Coverage 95.07% 94.87% -0.20%
==========================================
Files 33 33
Lines 2883 2889 +6
Branches 456 456
==========================================
Hits 2741 2741
- Misses 142 148 +6 ☔ View full report in Codecov by Sentry. |
Co-authored-by: antoniopresto <[email protected]>
+1 tested quickly via this loader and it fixed {
test: /node_modules[\\/]@ant-design[\\/]cssinjs[\\/]es[\\/]hooks[\\/]useHMR\.js$/, // https://github.com/ant-design/cssinjs/issues/133
loader: "string-replace-loader",
options: {
search: "window",
replace: "globalThis",
flags: "g",
},
}, |
Hi! Do you need any help on this? :) |
📝 WalkthroughWalkthrough此次更改主要涉及 Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
src/hooks/useHMR.ts (1)
22-27
: 建议简化全局对象访问逻辑当前实现使用了多层条件判断来访问全局对象。考虑到
globalThis
在现代运行时环境中的广泛支持,建议采用更简洁的方式。建议修改为:
- const win = - typeof globalThis !== 'undefined' - ? globalThis - : ((typeof window !== 'undefined' ? window : null) as any); + const win = globalThis as any;这样的修改可以:
- 减少代码复杂度
- 提高代码可读性
- 符合现代 JavaScript 最佳实践
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/hooks/useHMR.ts
(1 hunks)
🔇 Additional comments (1)
src/hooks/useHMR.ts (1)
29-29
: 对全局对象的空值检查是个很好的改进
添加 win &&
检查可以防止在不支持相关全局对象的环境中出现运行时错误,这是一个很好的防御性编程实践。
Usage of
window
in non-browser env, breaksSummary by CodeRabbit
globalThis
的优先支持,以提高在非生产环境中的稳定性。