ant-design / cssinjs

https://ant-design.github.io/cssinjs
MIT License
236 stars 59 forks source link

use globalThis instead of window in HMR #134

Open MaxArtemov opened 11 months ago

MaxArtemov commented 11 months ago

Usage of window in non-browser env, breaks

antoniopresto commented 11 months ago

+ 1

This fixes window is not defined in next.js "edge runtimes"

for more context: https://wintercg.org/

The ultimate goal of the group is to promote runtimes supporting a comprehensive unified API surface that JavaScript developers can rely on regardless of the runtime they are using: be it browsers, servers, embedded applications, or edge runtimes. The members of the group want to provide a space to better coordinate between browser vendors and other implementors on how Web Platform APIs can be best implemented and used outside of browsers.

codecov-commenter commented 11 months ago

Codecov Report

Patch coverage: 87.17% and project coverage change: -0.06% :warning:

Comparison is base (55d5716) 94.80% compared to head (89f350b) 94.75%. Report is 10 commits behind head on master.

:exclamation: Current head 89f350b differs from pull request most recent head 430abbf. Consider uploading reports for the commit 430abbf to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #134 +/- ## ========================================== - Coverage 94.80% 94.75% -0.06% ========================================== Files 24 24 Lines 2041 2115 +74 Branches 321 330 +9 ========================================== + Hits 1935 2004 +69 - Misses 106 111 +5 ``` | [Files Changed](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design) | Coverage Δ | | |---|---|---| | [src/hooks/useHMR.ts](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design#diff-c3JjL2hvb2tzL3VzZUhNUi50cw==) | `52.94% <33.33%> (-1.61%)` | :arrow_down: | | [src/hooks/useGlobalCache.tsx](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design#diff-c3JjL2hvb2tzL3VzZUdsb2JhbENhY2hlLnRzeA==) | `93.93% <78.57%> (-2.62%)` | :arrow_down: | | [src/hooks/useStyleRegister/index.tsx](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design#diff-c3JjL2hvb2tzL3VzZVN0eWxlUmVnaXN0ZXIvaW5kZXgudHN4) | `98.11% <87.34%> (-0.03%)` | :arrow_down: | | [src/hooks/useCacheToken.tsx](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design#diff-c3JjL2hvb2tzL3VzZUNhY2hlVG9rZW4udHN4) | `99.44% <100.00%> (+0.04%)` | :arrow_up: | | [src/util.ts](https://app.codecov.io/gh/ant-design/cssinjs/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ant-design#diff-c3JjL3V0aWwudHM=) | `40.54% <100.00%> (+1.65%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

XavierLeTohic commented 11 months ago

+1 tested quickly via this loader and it fixed window is not defined using renderToPipeableStream from react-dom/server with Express

{
  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",
  },
},
antoniopresto commented 10 months ago

Hi! Do you need any help on this? :)