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

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

Open
jianan46 opened this issue Aug 2, 2024 · 3 comments
Open
Labels

Comments

@jianan46
Copy link

jianan46 commented Aug 2, 2024

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...
[email protected]: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
[email protected]:2888 停留时长11986
[email protected]:2875 页面进入:entryPage
@jianan46 jianan46 added the bug label Aug 2, 2024
@jianan46
Copy link
Author

jianan46 commented Aug 2, 2024

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

@wangzp93
Copy link

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

@jianan46
Copy link
Author

jianan46 commented Sep 4, 2024

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants