ant-design / ant-design-mobile

Essential UI blocks for building mobile web apps.
https://mobile.ant.design
MIT License
11.66k stars 2.4k forks source link

某些情况下document.body为null时,convert-px.js会抛出异常 #6694

Open jianan46 opened 3 months ago

jianan46 commented 3 months ago

Version of antd-mobile

5.36.0

Operating system and its version

Others

Browser and its version

Chrome 126.0.6478.185(正式版本) (arm64)

Sandbox to reproduce

No response

What happened?

某些情况下document.body为null时,convert-px.js会抛出异常

covert-px.js文件中canUseDom判断条件不够严谨,需要同时检查document.body是否正常

Relevant log output

Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at inject_head_top.bdfdb2c0.js:21517:17
    at inject_head_top.bdfdb2c0.js:23077:2
    at inject_head_top.bdfdb2c0.js:23080:12
    at webpackUniversalModuleDefinition (inject_head_top.bdfdb2c0.js:1002:20)
    at Object.<anonymous> (inject_head_top.bdfdb2c0.js:1004:3)
    at ./node_modules/@didi/mfe-coverage-reporter/dist/main.js (inject_head_top.bdfdb2c0.js:23084:30)
    at __webpack_require__ (inject_head_top.bdfdb2c0.js:734:30)
    at fn (inject_head_top.bdfdb2c0.js:111:20)
    at ./node_modules/@didi/webpack-coverage-reporter/src/reporter.js (inject_head_top.bdfdb2c0.js:23095:27)
    at __webpack_require__ (inject_head_top.bdfdb2c0.js:734:30)
(anonymous) @ inject_head_top.bdfdb2c0.js:21517
(anonymous) @ inject_head_top.bdfdb2c0.js:23077
(anonymous) @ inject_head_top.bdfdb2c0.js:23080
webpackUniversalModuleDefinition @ inject_head_top.bdfdb2c0.js:1002
(anonymous) @ inject_head_top.bdfdb2c0.js:1004
./node_modules/@didi/mfe-coverage-reporter/dist/main.js @ inject_head_top.bdfdb2c0.js:23084
__webpack_require__ @ inject_head_top.bdfdb2c0.js:734
fn @ inject_head_top.bdfdb2c0.js:111
./node_modules/@didi/webpack-coverage-reporter/src/reporter.js @ inject_head_top.bdfdb2c0.js:23095
__webpack_require__ @ inject_head_top.bdfdb2c0.js:734
fn @ inject_head_top.bdfdb2c0.js:111
3 @ inject_head_top.bdfdb2c0.js:34130
__webpack_require__ @ inject_head_top.bdfdb2c0.js:734
(anonymous) @ inject_head_top.bdfdb2c0.js:801
(anonymous) @ inject_head_top.bdfdb2c0.js:804
webpackUniversalModuleDefinition @ inject_head_top.bdfdb2c0.js:7
(anonymous) @ inject_head_top.bdfdb2c0.js:10
start.bdfdb2c0.js:35154 [HMR] Waiting for update signal from WDS...
start.bdfdb2c0.js:879 Uncaught TypeError: window.timeLog is not a function
    at ./client/start.ts (start.bdfdb2c0.js:879:8)
    at __webpack_require__ (start.bdfdb2c0.js:734:30)
    at fn (start.bdfdb2c0.js:111:20)
    at 0 (start.bdfdb2c0.js:35192:18)
    at __webpack_require__ (start.bdfdb2c0.js:734:30)
    at start.bdfdb2c0.js:801:37
    at start.bdfdb2c0.js:804:10
    at webpackUniversalModuleDefinition (start.bdfdb2c0.js:7:127)
    at start.bdfdb2c0.js:10:3
./client/start.ts @ start.bdfdb2c0.js:879
__webpack_require__ @ start.bdfdb2c0.js:734
fn @ start.bdfdb2c0.js:111
0 @ start.bdfdb2c0.js:35192
__webpack_require__ @ start.bdfdb2c0.js:734
(anonymous) @ start.bdfdb2c0.js:801
(anonymous) @ start.bdfdb2c0.js:804
webpackUniversalModuleDefinition @ start.bdfdb2c0.js:7
(anonymous) @ start.bdfdb2c0.js:10
inject_body_top.bdfdb2c0.js:33764 [HMR] Waiting for update signal from WDS...
vendors-._node_modules_l.3395eb4.js:24968 [HMR] Waiting for update signal from WDS...
vendors-._node_modules_@.d244817.js:1372 [system] Location: http://localhost:9102/heranew/?hash_passport_login=#?hash_passport_login
app.bdfdb2c0.js:1039 Uncaught TypeError: window.timeLog is not a function
    at ./client/app.ts (app.bdfdb2c0.js:1039:8)
    at __webpack_require__ (app.bdfdb2c0.js:816:30)
    at fn (app.bdfdb2c0.js:174:20)
    at 1 (app.bdfdb2c0.js:43808:18)
    at __webpack_require__ (app.bdfdb2c0.js:816:30)
    at checkDeferredModules (app.bdfdb2c0.js:70:23)
    at app.bdfdb2c0.js:1007:18
    at app.bdfdb2c0.js:1010:10
    at webpackUniversalModuleDefinition (app.bdfdb2c0.js:7:185)
    at app.bdfdb2c0.js:10:3
./client/app.ts @ app.bdfdb2c0.js:1039
__webpack_require__ @ app.bdfdb2c0.js:816
fn @ app.bdfdb2c0.js:174
1 @ app.bdfdb2c0.js:43808
__webpack_require__ @ app.bdfdb2c0.js:816
checkDeferredModules @ app.bdfdb2c0.js:70
(anonymous) @ app.bdfdb2c0.js:1007
(anonymous) @ app.bdfdb2c0.js:1010
webpackUniversalModuleDefinition @ app.bdfdb2c0.js:7
(anonymous) @ app.bdfdb2c0.js:10
vendors-._node_modules_@.d244817.js:2888 停留时长11986
vendors-._node_modules_@.d244817.js:2875 页面进入:entryPage
jianan46 commented 3 months ago

我根据我的理解修改了判断条件后,我的代码可以正常运行了,pr:#6693

wangzp93 commented 2 months ago

image 看下你的 HtmlWebpackPlugin 配置,是不是把 inject 配成 'head' 了。我也遇到同样的问题,改成 'body' 就可以了。这段代码执行时机太早的话 document.body 会拿不到

jianan46 commented 2 months ago

image 看下你的 HtmlWebpackPlugin 配置,是不是把 inject 配成 'head' 了。我也遇到同样的问题,改成 'body' 就可以了。这段代码执行时机太早的话 document.body 会拿不到

但是我确实有东西需要注入到head里面