Skip to content

Commit 0c2e2dd

Browse files
committed
Merge branch 'dev'
2 parents 153239a + 1ea57d6 commit 0c2e2dd

File tree

8 files changed

+38
-6
lines changed

8 files changed

+38
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ For more commands, see [DEVELOP](https://github.com/jd-opensource/micro-app/blob
149149

150150
# Contributors
151151
<a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
152-
<img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
152+
<img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
153153
</a>
154154

155155
# License

README.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ yarn start # 访问 http://localhost:3000
148148

149149
# 贡献者们
150150
<a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
151-
<img src="https://contrib.rocks/image?repo=micro-zoe/micro-app" />
151+
<img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
152152
</a>
153153

154154

docs/zh-cn/changelog.md

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

99
---
10+
### 1.0.0-rc.19
11+
12+
`2025-01-15`
13+
- **Bug Fix**
14+
- 🐞 修复 子应用渲染之后,使用Html2Canvas截图,页面崩溃,无限循环加载当前页面静态资源 [issue 1483](https://github.com/jd-opensource/micro-app/issues/1483)
15+
- 🐞 修复 vite热更样式隔离丢失问题
16+
1017
### 1.0.0-rc.18
1118

1219
`2024-12-16`

package.json

+1-1
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.18",
3+
"version": "1.0.0-rc.19",
44
"description": "A lightweight, efficient and powerful micro front-end framework",
55
"private": false,
66
"main": "lib/index.min.js",

src/create_app.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface CreateAppParam {
5252
ssrUrl?: string
5353
isPrefetch?: boolean
5454
prefetchLevel?: number
55+
attrs?: Record<string, string>,
5556
routerMode?: string
5657
}
5758

@@ -79,6 +80,7 @@ export default class CreateApp implements AppInterface {
7980
public prefetchLevel?: number
8081
public fiber = false
8182
public routerMode: string
83+
public attrs?: Record<string, string>
8284

8385
constructor ({
8486
name,
@@ -92,13 +94,15 @@ export default class CreateApp implements AppInterface {
9294
isPrefetch,
9395
prefetchLevel,
9496
routerMode,
97+
attrs,
9598
}: CreateAppParam) {
9699
appInstanceMap.set(name, this)
97100
// init actions
98101
this.name = name
99102
this.url = url
100103
this.useSandbox = useSandbox
101104
this.scopecss = this.useSandbox && scopecss
105+
this.attrs = attrs
102106
// exec before getInlineModeState
103107
this.iframe = iframe ?? false
104108
this.inline = this.getInlineModeState(inline)
@@ -758,7 +762,7 @@ export default class CreateApp implements AppInterface {
758762
*/
759763
private createSandbox (): void {
760764
if (this.useSandbox && !this.sandBox) {
761-
this.sandBox = this.iframe ? new IframeSandbox(this.name, this.url) : new WithSandBox(this.name, this.url)
765+
this.sandBox = this.iframe ? new IframeSandbox(this.name, this.url, { attrs: this.attrs }) : new WithSandBox(this.name, this.url)
762766
}
763767
}
764768

src/micro_app_element.ts

+8
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ export function defineElement (tagName: string): void {
353353

354354
// create app instance
355355
private handleCreateApp (): void {
356+
const attrs: Record<string, string> = {}
357+
Array.prototype.slice.call(this.attributes).forEach(({ name, value }: Attr) => {
358+
if (name.startsWith('data-')) {
359+
attrs[name] = value
360+
}
361+
})
362+
356363
const createAppInstance = () => new CreateApp({
357364
name: this.appName,
358365
url: this.appUrl,
@@ -363,6 +370,7 @@ export function defineElement (tagName: string): void {
363370
iframe: this.getDisposeResult('iframe'),
364371
ssrUrl: this.ssrUrl,
365372
routerMode: this.getMemoryRouterMode(),
373+
attrs
366374
})
367375

368376
/**

src/sandbox/iframe/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ export default class IframeSandbox {
8181
// TODO: 放到 super中定义,super(appName, url),with沙箱也需要简化
8282
public appName: string
8383
public url: string
84+
public options?: Record<string, any>
8485
// reset mount, unmount when stop in default mode
8586
public clearHijackUmdHooks!: () => void
8687

87-
constructor (appName: string, url: string) {
88+
constructor (appName: string, url: string, options: Record<string, any>) {
8889
this.appName = appName
8990
this.url = url
91+
this.options = options
9092
const rawLocation = globalEnv.rawWindow.location
9193
const browserHost = rawLocation.protocol + '//' + rawLocation.host
9294

93-
this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname)
95+
this.deleteIframeElement = this.createIframeElement(appName, browserHost + rawLocation.pathname, options)
9496
this.microAppWindow = this.iframe!.contentWindow
9597

9698
this.patchIframe(this.microAppWindow, (resolve: CallableFunction) => {
@@ -126,10 +128,12 @@ export default class IframeSandbox {
126128
createIframeElement (
127129
appName: string,
128130
browserPath: string,
131+
options?: Record<string, any>
129132
): () => void {
130133
this.iframe = pureCreateElement('iframe')
131134

132135
const iframeAttrs: Record<string, string> = {
136+
...options?.attrs,
133137
id: appName,
134138
src: microApp.options.iframeSrc || browserPath,
135139
style: 'display: none',

src/sandbox/scoped_css.ts

+9
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,15 @@ export default function scopedCSS (
518518
app.url,
519519
linkPath,
520520
)
521+
const observer = new MutationObserver(() => {
522+
const isPrefixed = styleElement.textContent && new RegExp(prefix).test(styleElement.textContent)
523+
observer.disconnect()
524+
if (!isPrefixed) {
525+
styleElement.__MICRO_APP_HAS_SCOPED__ = false
526+
}
527+
scopedCSS(styleElement, app, linkPath)
528+
})
529+
observer.observe(styleElement, { childList: true, characterData: true })
521530
} else {
522531
const observer = new MutationObserver(function () {
523532
observer.disconnect()

0 commit comments

Comments
 (0)