-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: runtime should compat with old browsers #6478
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #6478 +/- ##
==========================================
- Coverage 80.18% 80.13% -0.05%
==========================================
Files 240 240
Lines 21599 21617 +18
Branches 2655 2663 +8
==========================================
+ Hits 17319 17323 +4
- Misses 4236 4250 +14
Partials 44 44
☔ View full report in Codecov by Sentry. |
packages/runtime/src/Suspense.tsx
Outdated
@@ -157,6 +166,6 @@ function Data(props) { | |||
const data = useSuspenseData(); | |||
|
|||
return ( | |||
<script dangerouslySetInnerHTML={{ __html: `if (!window.${LOADER}) { window.${LOADER} = new Map();} window.${LOADER}.set('${props.id}', ${JSON.stringify(data)})` }} /> | |||
<script dangerouslySetInnerHTML={{ __html: `!function(){if (!window.${LOADER}) { window['${LOADER}'] = {};} window['${LOADER}']['${props.id}'] = ${JSON.stringify(data)}}();` }} /> |
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.
这里会是一个 breaking change 了, 假设有人调用了这个全局变量, 那么获取方式会发生变化
PS: 当然不应该调用这个私有变量
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.
var d = window['${LOADER}'] || {};
d['${props.id']=xxx;
window['${LOADER}'] = d;
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.
还有没有更少的版本
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.
这里会是一个 breaking change 了, 假设有人调用了这个全局变量, 那么获取方式会发生变化
PS: 当然不应该调用这个私有变量
嗯 理论上不应该显示调用,后面可以单独沟通下重点已接入业务
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.
var d = window['${LOADER}'] || {}; d['${props.id']=xxx; window['${LOADER}'] = d;
window['${LOADER}'] = window['${LOADER}'] || {};
window['${LOADER}']['${props.id']=xxx;
对比这样没啥优势 - -
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.
优势: 少了一次 window['xxx']
劣势: 多了一个变量, 导致必须函数闭包一下
* fix: runtime should compat with old browsers * fix: optimize code * fix: lint * chore: optimize code * chore: optimize code
Compat runtime code with old browsers which depend on
Object.assgin
andMap
.