Skip to content

Commit 4c290f7

Browse files
committed
Merge branch 'dev'
2 parents 8eb8ccb + 0064a91 commit 4c290f7

File tree

7 files changed

+44
-17
lines changed

7 files changed

+44
-17
lines changed

docs/zh-cn/advanced.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,22 @@ microApp.start({
8484
})
8585
```
8686

87-
## escapeIframeWindowEvents : iframe 模式 逃逸沙盒的window事件
87+
## 5、escapeIframeWindowEvents : iframe 模式 逃逸沙盒的window事件
8888
```js
8989
import microApp from '@micro-zoe/micro-app'
9090

9191
microApp.start({
92-
// 子应用的
92+
// 配置所有iframe子应用 逃逸沙盒的window事件
9393
escapeIframeWindowEvents: ['message']
9494
})
9595
```
96+
## 6、disableIframeRootDocument : iframe模式禁用沙箱Document 默认为false
97+
```js
98+
import microApp from '@micro-zoe/micro-app'
9699

100+
microApp.start({
101+
// iframe模式禁用沙箱Document,避免一些ui组件库Modal 或tooltip 偏移
102+
disableIframeRootDocument: true
103+
})
104+
```
97105

docs/zh-cn/changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
- 修订版本号:每周末会进行日常 bugfix 更新。(如果有紧急的 bugfix,则任何时候都可发布)
88

99
---
10+
### 1.0.0-rc.26
11+
12+
`2025-05-25`
13+
- **Feature**
14+
- 支持 disableIframeRootDocument : iframe模式禁用沙箱Document,默认为false。
1015
### 1.0.0-rc.25
1116

1217
`2025-05-23`
1318
- **Feature**
14-
- 支持escapeIframeWindowEvents : iframe 模式 逃逸沙盒的window事件。
19+
- 支持escapeIframeWindowEvents : iframe 模式 逃逸沙盒的window事件, Array<string>
1520
- **Bug Fix**
1621
- 🐞 修复 子应用样式加载异常,[issue 1553](https://github.com/jd-opensource/micro-app/issues/1553)
1722
- 🐞 修复 当开启样式隔离时子应用属性选择器样式错误,[issue 1573](https://github.com/jd-opensource/micro-app/issues/1573)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@micro-zoe/micro-app",
3-
"version": "1.0.0-rc.25",
3+
"version": "1.0.0-rc.26",
44
"description": "A lightweight, efficient and powerful micro front-end framework",
55
"private": false,
66
"main": "lib/index.min.js",

src/sandbox/adapter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,14 @@ export function getIframeParentNodeDesc (
250250
* e.g. target.parentNode.remove(target)
251251
*/
252252
if (isMicroAppBody(result) && appInstanceMap.get(appName)?.container) {
253-
return microApp.options.getRootElementParentNode?.(this, appName) || globalEnv.rawDocument.body
253+
const customParent = microApp.options.getRootElementParentNode?.(this, appName)
254+
if (customParent) {
255+
return customParent
256+
}
257+
if (microApp?.options?.inheritBaseBody !== true) {
258+
return appInstanceMap.get(appName)?.container?.querySelector('micro-app-body') || globalEnv.rawDocument.body
259+
}
260+
return globalEnv.rawDocument.body
254261
}
255262
return result
256263
}

src/sandbox/iframe/document.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ export function patchDocument (
5454

5555
return patchDocumentEffect(appName, microAppWindow)
5656
}
57+
function getElementDocument(microDocument: Document, rawDocument: Document): Document {
58+
if (microApp?.options?.disableIframeRootDocument) {
59+
return rawDocument
60+
}
61+
return microDocument
62+
}
5763

5864
function patchDocumentPrototype (appName: string, microAppWindow: microAppWindowType): void {
5965
const rawDocument = globalEnv.rawDocument
@@ -88,7 +94,7 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
8894
tagName: string,
8995
options?: ElementCreationOptions,
9096
): HTMLElement {
91-
let element = rawMicroCreateElement.call(this, tagName, options)
97+
let element = rawMicroCreateElement.call(getElementDocument(this, rawDocument), tagName, options)
9298
if (isWebComponentElement(element)) {
9399
element = rawMicroCreateElement.call(rawDocument, tagName, options)
94100
}
@@ -100,22 +106,22 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
100106
name: string,
101107
options?: string | ElementCreationOptions,
102108
): HTMLElement {
103-
const element = rawMicroCreateElementNS.call(this, namespaceURI, name, options)
109+
const element = rawMicroCreateElementNS.call(getElementDocument(this, rawDocument), namespaceURI, name, options)
104110
return updateElementInfo(element, appName)
105111
}
106112

107113
microRootDocument.prototype.createTextNode = function createTextNode (data: string): Text {
108-
const element = rawMicroCreateTextNode.call(this, data)
114+
const element = rawMicroCreateTextNode.call(getElementDocument(this, rawDocument), data)
109115
return updateElementInfo<Text>(element, appName)
110116
}
111117

112118
microRootDocument.prototype.createDocumentFragment = function createDocumentFragment (): DocumentFragment {
113-
const element = rawMicroCreateDocumentFragment.call(this)
119+
const element = rawMicroCreateDocumentFragment.call(getElementDocument(this, rawDocument))
114120
return updateElementInfo(element, appName)
115121
}
116122

117123
microRootDocument.prototype.createComment = function createComment (data: string): Comment {
118-
const element = rawMicroCreateComment.call(this, data)
124+
const element = rawMicroCreateComment.call(getElementDocument(this, rawDocument), data)
119125
return updateElementInfo<Comment>(element, appName)
120126
}
121127

@@ -184,7 +190,7 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
184190
}
185191

186192
try {
187-
return querySelector.call(this, `#${key}`)
193+
return querySelector.call(getElementDocument(this, rawDocument), `#${key}`)
188194
} catch {
189195
return rawMicroGetElementById.call(_this, key)
190196
}
@@ -197,14 +203,14 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
197203
}
198204

199205
try {
200-
return querySelectorAll.call(this, `.${key}`)
206+
return querySelectorAll.call(getElementDocument(this, rawDocument), `.${key}`)
201207
} catch {
202208
return rawMicroGetElementsByClassName.call(_this, key)
203209
}
204210
}
205211

206212
microRootDocument.prototype.getElementsByTagName = function getElementsByTagName (key: string): HTMLCollectionOf<Element> {
207-
const _this = getBindTarget(this)
213+
const _this = getBindTarget(getElementDocument(this, rawDocument))
208214
if (
209215
isUniqueElement(key) ||
210216
isInvalidQuerySelectorKey(key)
@@ -216,20 +222,20 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
216222
}
217223

218224
try {
219-
return querySelectorAll.call(this, key)
225+
return querySelectorAll.call(getElementDocument(this, rawDocument), key)
220226
} catch {
221227
return rawMicroGetElementsByTagName.call(_this, key)
222228
}
223229
}
224230

225231
microRootDocument.prototype.getElementsByName = function getElementsByName (key: string): NodeListOf<HTMLElement> {
226-
const _this = getBindTarget(this)
232+
const _this = getBindTarget(getElementDocument(this, rawDocument))
227233
if (isInvalidQuerySelectorKey(key)) {
228234
return rawMicroGetElementsByName.call(_this, key)
229235
}
230236

231237
try {
232-
return querySelectorAll.call(this, `[name=${key}]`)
238+
return querySelectorAll.call(getElementDocument(this, rawDocument), `[name=${key}]`)
233239
} catch {
234240
return rawMicroGetElementsByName.call(_this, key)
235241
}

src/sandbox/iframe/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function patchWindowEffect (microAppWindow: microAppWindowType): CommonEffectHoo
237237
*/
238238
let escapeSandboxEvent: Array<string> = []
239239
if (Array.isArray(microApp?.options?.escapeIframeWindowEvents)) {
240-
escapeSandboxEvent = microApp?.options?.escapeIframeWindowEvents
240+
escapeSandboxEvent = microApp.options.escapeIframeWindowEvents
241241
}
242242
const scopeWindowEvent = SCOPE_WINDOW_EVENT_OF_IFRAME.filter(item => !escapeSandboxEvent.includes(item))
243243
return scopeWindowEvent.includes(type) ? microAppWindow : rawWindow

typings/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ declare module '@micro-app/types' {
371371
aHrefResolver?: (hrefValue: string, appName: string, appUrl: string) => string
372372
inheritBaseBody?:boolean,
373373
escapeIframeWindowEvents? : Array<string>,
374+
disableIframeRootDocument?: boolean,
374375
}
375376

376377
// MicroApp config

0 commit comments

Comments
 (0)