Skip to content

Commit aa0a559

Browse files
author
huangchenbj
committed
Merge branch 'fix/script-load-error' into cosmo-dev
2 parents 9faa8b7 + abe9fbf commit aa0a559

File tree

13 files changed

+123
-48
lines changed

13 files changed

+123
-48
lines changed

Contact.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11

22
欢迎小伙伴们加入micro-app微信群交流^ ^
3-
![image](https://github.com/user-attachments/assets/46ff4638-1c25-4458-b0f5-e547da16b162)
3+
![0291aea2443d8ef10404880c8b64593a](https://github.com/user-attachments/assets/0cb4d5d4-d18b-4131-910c-87ccfc1628e8)
4+
5+
6+
欢迎小伙伴们加入micro-app-DevTools开发交流群^ ^
7+
![d57424c8597f124d03510e0cb023a020](https://github.com/user-attachments/assets/b9725704-46a4-4cf1-99fd-79596c027128)
8+
9+
10+
11+
12+
13+
14+
15+
16+
417

518

619

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`

docs/zh-cn/micro-app-devtools.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# 📖简介
22
`Micro-App-DevTools`是基于京东零售推出的一款为`micro-app`框架而开发的`chrome`插件,旨在方便开发者对微前端进行数据查看以及调试,提升工作效率。
3-
Github 地址为:[https://github.com/micro-zoe/micro-app-chrome-plugin](https://github.com/micro-zoe/micro-app-chrome-plugin),欢迎 Star 一下
43

54
# 如何使用
65

7-
在chrome中输入`chrome://extensions`打开扩展程序,打开[插件下载地址](https://github.com/micro-zoe/micro-app-chrome-plugin/releases),选择最新Release包的`micro-app-chrome-plugin.zip`
6+
在chrome中输入`chrome://extensions`打开扩展程序,打开[插件下载地址](https://github.com/jd-opensource/micro-app-chrome-plugin/releases),选择最新Release包的`micro-app-chrome-plugin.zip`
87
文件下载,无需解压,将已下载的插件拖入。
98

109
![扩展程序](https://img12.360buyimg.com/imagetools/jfs/t1/119438/16/38287/53001/646b50e3F9012f2e8/3bba9844bbb1431b.png)
@@ -49,7 +48,7 @@ Github 地址为:[https://github.com/micro-zoe/micro-app-chrome-plugin](https:
4948
#### 快捷打开方式二
5049
点击鼠标右键,选择micro-app下,二级菜单点子应用开发环境模拟
5150

52-
![快捷方式](https://github.com/micro-zoe/micro-app-chrome-plugin/assets/14011130/91b40f7c-a826-4ffe-8c20-0b43a5c3bc6f)
51+
![快捷方式](https://github.com/jd-opensource/micro-app-chrome-plugin/assets/14011130/91b40f7c-a826-4ffe-8c20-0b43a5c3bc6f)
5352

5453

5554
## 常见问题
@@ -61,8 +60,7 @@ Github 地址为:[https://github.com/micro-zoe/micro-app-chrome-plugin](https:
6160

6261
## 🤝 参与共建
6362

64-
如果您对这个项目感兴趣,欢迎提[pull request](https://github.com/micro-zoe/micro-app-chrome-plugin/pulls)参与贡献,也欢迎 [Star](https://github.com/micro-zoe/micro-app-chrome-plugin) 支持一下 ^_^
65-
欢迎小伙伴们加入`Micro-App-DevTools`微信群交流^ ^
63+
如果您对这个项目感兴趣,欢迎提[pull request](https://github.com/jd-opensource/micro-app-chrome-plugin/pulls)参与贡献,也欢迎 [Star](https://github.com/jd-opensource/micro-app-chrome-plugin) 支持一下 ^_^
6664

67-
![image](https://img12.360buyimg.com/imagetools/jfs/t1/29962/13/20207/70265/646c9851Fe104e7c1/fed2ab97e2cf5f29.png)
65+
[欢迎小伙伴们加入Micro-App微信群交流^ ^](https://github.com/jd-opensource/micro-app/blob/master/Contact.md)
6866

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/create_app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default class CreateApp implements AppInterface {
7979
public isPrefetch: boolean
8080
public isPrerender: boolean
8181
public prefetchLevel?: number
82+
public mountIdentifier?: symbol
8283
public fiber = false
8384
public routerMode: string
8485
public attrs?: Record<string, string>
@@ -288,6 +289,7 @@ export default class CreateApp implements AppInterface {
288289
this.routerMode = routerMode
289290

290291
const dispatchBeforeMount = () => {
292+
this.mountIdentifier = Symbol('mountIdentifier')
291293
dispatchLifecyclesEvent(
292294
this.container,
293295
this.name,
@@ -494,6 +496,8 @@ export default class CreateApp implements AppInterface {
494496
unmountcb?: CallableFunction,
495497
umdHookUnmountResult?: unknown,
496498
): void {
499+
this.mountIdentifier = undefined
500+
497501
// dispatch state event to micro app
498502
dispatchCustomEventToMicroApp(this, 'statechange', {
499503
appState: appStates.UNMOUNT

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
})

0 commit comments

Comments
 (0)