Skip to content

Commit 1660461

Browse files
committed
feat: 子应用是否采用基座body&子应用支持addEventListener('error')捕捉自身异常
1 parent fa7c7db commit 1660461

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

docs/zh-cn/advanced.md

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ microApp.start({
5959
})
6060
```
6161

62+
## 3、inheritBaseBody: 子应用body标签是否采用基座标签,默认不采用
63+
`true`: 采用
64+
`false`: 不采用
65+
66+
6267

6368
> [!NOTE]
6469
> 需要注意的是,如果跨域请求带cookie,那么`Access-Control-Allow-Origin`不能设置为`*`,必须指定域名,同时设置`Access-Control-Allow-Credentials: true`

src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const BASE_SCOPE_WINDOW_EVENT = [
110110
'appstate-change',
111111
'statechange',
112112
'mounted',
113+
'error'
113114
// 'beforeunload', // remove at 2024.5.30 by cangdu
114115
]
115116

src/sandbox/iframe/document.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import {
3434
appInstanceMap,
3535
} from '../../create_app'
36+
import microApp from '../../micro_app'
3637

3738
/**
3839
* TODO: 1、shadowDOM 2、结构优化
@@ -133,7 +134,7 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
133134
// query element👇
134135
function querySelector (this: Document, selectors: string): any {
135136
const _this = getBindTarget(this)
136-
if (selectors === 'body') {
137+
if (selectors === 'body' && microApp?.options?.inheritBaseBody !== true) {
137138
return this.body
138139
}
139140
if (
@@ -305,7 +306,7 @@ function patchDocumentProperty (
305306
configurable: true,
306307
get: () => {
307308
throttleDeferForIframeAppName(appName)
308-
if (tagName === 'body') {
309+
if (tagName === 'body' && microApp?.options?.inheritBaseBody !== true) {
309310
return sandbox.options.container?.querySelector('micro-app-body') || rawDocument[tagName]
310311
}
311312
return rawDocument[tagName]

typings/global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ declare module '@micro-app/types' {
368368
includeCrossOrigin?: (assetUrl: string) => boolean
369369
getRootElementParentNode?: (node: Node, appName: AppName) => void
370370
customProxyDocumentProps?: Map<string | number | symbol, (value: unknown) => void>
371+
inheritBaseBody?:boolean
371372
}
372373

373374
// MicroApp config

0 commit comments

Comments
 (0)