Skip to content

Commit 8d03442

Browse files
committed
Merge branch 'master' into feat_enhui_fix
2 parents 7d1a815 + b575fdd commit 8d03442

File tree

10 files changed

+2974
-3210
lines changed

10 files changed

+2974
-3210
lines changed

Contact.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11

22
欢迎小伙伴们加入micro-app微信群交流^ ^
3-
![IMG_3890](https://github.com/user-attachments/assets/7c4dc938-c69e-40ce-8fb8-9fb23c0f7013)
3+
![f08d41cdea5a364a9277d443e90f2f25](https://github.com/user-attachments/assets/47bf5fcb-60a6-48b5-81e1-31302e10b1e9)
4+
5+
6+
47

58

69
欢迎小伙伴们加入micro-app-DevTools开发交流群^ ^
7-
![image](https://github.com/user-attachments/assets/a73aa2d6-945c-40fb-89a2-225ad4430c52)
10+
![5795b83d20722041992bc38f6917f25d](https://github.com/user-attachments/assets/bdfc12e8-982a-4772-8d80-82dc23ec1647)
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
821

922

1023

docs/zh-cn/advanced.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,34 @@ microApp.start({
7272
})
7373
```
7474

75-
// 配置所有子应用 a 标签的 href 自动补齐方式
76-
aHrefResolver: (hrefValue: string, appName: string, appUrl: string) => {
77-
return 'https://www.abc.com/'+ hrefValue
78-
}
79-
80-
81-
8275
## 4、aHrefResolver: 自定义处理所有子应用 a 标签的 href 拼接方式
83-
8476
```js
8577
import microApp from '@micro-zoe/micro-app'
8678

8779
microApp.start({
80+
// 配置所有子应用 a 标签的 href 自动补齐方式
8881
aHrefResolver: (hrefValue: string, appName: string, appUrl: string) => {
8982
return 'https://www.abc.com/'+ hrefValue
9083
}
9184
})
9285
```
9386

87+
## 5、escapeIframeWindowEvents : iframe 模式 逃逸沙盒的window事件
88+
```js
89+
import microApp from '@micro-zoe/micro-app'
90+
91+
microApp.start({
92+
// 配置所有iframe子应用 逃逸沙盒的window事件
93+
escapeIframeWindowEvents: ['message']
94+
})
95+
```
96+
## 6、disableIframeRootDocument : iframe模式禁用沙箱Document 默认为false
97+
```js
98+
import microApp from '@micro-zoe/micro-app'
99+
100+
microApp.start({
101+
// iframe模式禁用沙箱Document,避免一些ui组件库Modal 或tooltip 偏移
102+
disableIframeRootDocument: true
103+
})
104+
```
94105

docs/zh-cn/changelog.md

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

99
---
10+
### 1.0.0-rc.26
1011

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

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

1425
`2025-03-19`

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.24",
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
escape2RawWindowRegExpKeys,
2626
} from './special_key'
2727
import WorkerProxy from '../../proxies/worker'
28+
import microApp from '../../micro_app'
2829

2930
/**
3031
* patch window of child app
@@ -234,7 +235,12 @@ function patchWindowEffect (microAppWindow: microAppWindowType): CommonEffectHoo
234235
* TODO: SCOPE_WINDOW_EVENT_OF_IFRAME的事件非常少,有可能导致问题
235236
* 1、一些未知的需要绑定到iframe的事件被错误的绑定到原生window上
236237
*/
237-
return SCOPE_WINDOW_EVENT_OF_IFRAME.includes(type) ? microAppWindow : rawWindow
238+
let escapeSandboxEvent: Array<string> = []
239+
if (Array.isArray(microApp?.options?.escapeIframeWindowEvents)) {
240+
escapeSandboxEvent = microApp.options.escapeIframeWindowEvents
241+
}
242+
const scopeWindowEvent = SCOPE_WINDOW_EVENT_OF_IFRAME.filter(item => !escapeSandboxEvent.includes(item))
243+
return scopeWindowEvent.includes(type) ? microAppWindow : rawWindow
238244
}
239245

240246
// TODO: listener 是否需要绑定microAppWindow,否则函数中的this指向原生window

src/sandbox/scoped_css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class CSSParser {
108108
* should be ==> micro-app[name=xxx] :where(.a, .b, .c) a {}
109109
*/
110110
const attributeValues: {[key: string]: any} = {}
111-
const matchRes = m[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g, (match, p1, p2) => {
112-
const mock = `__mock_${p1}Value__`
111+
const matchRes = m[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g, (match, p1, p2, offset) => {
112+
const mock = `__mock_${p1}_${offset}Value__`
113113
attributeValues[mock] = p2
114114
return match.replace(p2, mock)
115115
})

typings/global.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ declare module '@micro-app/types' {
369369
getRootElementParentNode?: (node: Node, appName: AppName) => void
370370
customProxyDocumentProps?: Map<string | number | symbol, (value: unknown) => void>
371371
aHrefResolver?: (hrefValue: string, appName: string, appUrl: string) => string
372-
inheritBaseBody?:boolean
372+
inheritBaseBody?:boolean,
373+
escapeIframeWindowEvents? : Array<string>,
374+
disableIframeRootDocument?: boolean,
373375
}
374376

375377
// MicroApp config

0 commit comments

Comments
 (0)