Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed Aug 20, 2024
2 parents 03e623a + b87562c commit 1d38027
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 8 additions & 0 deletions docs/zh-cn/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

---

### 1.0.0-rc.8

`2024-8-20`

- **Bug Fix**
- 🐞 修复 with沙箱下子应用重写`history.pushState``history.replaceState`失败的问题,[issue 1210](https://github.com/micro-zoe/micro-app/issues/1210)


### 1.0.0-rc.7

`2024-8-20`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@micro-zoe/micro-app",
"version": "1.0.0-rc.7",
"version": "1.0.0-rc.8",
"description": "A lightweight, efficient and powerful micro front-end framework",
"private": false,
"main": "lib/index.min.js",
Expand Down
5 changes: 2 additions & 3 deletions src/micro_app_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function defineElement (tagName: string): void {
if (
attr === ObservedAttrName.URL && (
!this.appUrl ||
!this.connectStateMap.get(this.connectedCount) // TODO: 这里的逻辑可否再优化一下
!this.connectStateMap.get(this.connectedCount)
)
) {
newVal = formatAppURL(newVal, this.appName)
Expand All @@ -159,7 +159,7 @@ export function defineElement (tagName: string): void {
} else if (
attr === ObservedAttrName.NAME && (
!this.appName ||
!this.connectStateMap.get(this.connectedCount) // TODO: 这里的逻辑可否再优化一下
!this.connectStateMap.get(this.connectedCount)
)
) {
const formatNewName = formatAppName(newVal)
Expand All @@ -168,7 +168,6 @@ export function defineElement (tagName: string): void {
return logError(`Invalid attribute name ${newVal}`, this.appName)
}

// TODO: 当micro-app还未插入文档中就修改name,逻辑可否再优化一下
if (this.cacheData) {
microApp.setData(formatNewName, this.cacheData)
this.cacheData = null
Expand Down
27 changes: 14 additions & 13 deletions src/sandbox/router/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,34 @@ export function createMicroHistory (appName: string, microLocation: MicroLocatio
}
}

const pushState = getMicroHistoryMethod('pushState')
const replaceState = getMicroHistoryMethod('replaceState')
const originalHistory = {
pushState: getMicroHistoryMethod('pushState'),
replaceState: getMicroHistoryMethod('replaceState'),
}

if (isIframeSandbox(appName)) {
return {
pushState,
replaceState,
return assign({
go (delta?: number) {
return rawHistory.go(delta)
}
} as MicroHistory
}, originalHistory) as MicroHistory
}

return new Proxy(rawHistory, {
get (target: History, key: PropertyKey): HistoryProxyValue {
if (key === 'state') {
if (key === 'pushState' || key === 'replaceState') {
return originalHistory[key]
} else if (key === 'state') {
return getMicroState(appName)
} else if (key === 'pushState') {
return pushState
} else if (key === 'replaceState') {
return replaceState
}
return bindFunctionToRawTarget<History, HistoryProxyValue>(Reflect.get(target, key), target, 'HISTORY')
},
set (target: History, key: PropertyKey, value: unknown): boolean {
Reflect.set(target, key, value)
if (key === 'pushState' || key === 'replaceState') {
originalHistory[key] = value as CallableFunction
} else {
Reflect.set(target, key, value)
}
/**
* If the set() method returns false, and the assignment happened in strict-mode code, a TypeError will be thrown.
* e.g. history.state = {}
Expand Down Expand Up @@ -219,7 +221,6 @@ function reWriteHistoryMethod (method: History['pushState' | 'replaceState']): C
excludeHiddenApp: true,
excludePreRender: true,
}).forEach(appName => {
// TODO: 大部分情况下,history.pushState 都是先执行,micro-app后卸载,所以会产生一种情况:跳转到新地址后,search模式会在url上添加参数,卸载后再将参数删除,所以会导致浏览器地址闪烁,是否需要去掉这个功能
if ((isRouterModeSearch(appName) || isRouterModeState(appName)) && !getMicroPathFromURL(appName)) {
const app = appInstanceMap.get(appName)!
attachRouteToBrowserURL(
Expand Down

0 comments on commit 1d38027

Please sign in to comment.