Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
timhub66 committed Sep 14, 2024
2 parents cd25a4d + 0024cb3 commit e9be667
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Contact.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

欢迎小伙伴们加入micro-app微信群交流^ ^

![IMG_0607](https://github.com/user-attachments/assets/a976245d-2d5e-460e-8bcb-421dbc31e494)
![IMG_0722](https://github.com/user-attachments/assets/4ca7569d-328d-4f28-aabe-f946b23bff3b)



Expand Down
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.10

`2024-9-14`

- **Bug Fix**
- 🐞 修复 子应用a标签href属性丢失,[issue 1358](https://github.com/micro-zoe/micro-app/issues/1358)


### 1.0.0-rc.9

`2024-9-10`
Expand Down
1 change: 0 additions & 1 deletion src/libs/global_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import {
updateElementInfo,
} from '../sandbox/adapter'
import '../proxies/worker'

declare global {
interface Node {
Expand Down
13 changes: 3 additions & 10 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ export function isNode(target: unknown): target is Node {
return target instanceof Node || isNumber((target as Node)?.nodeType)
}

export function isCanvasElement(target: unknown): target is HTMLAnchorElement {
export function isCanvasElement(target: unknown): target is HTMLCanvasElement {
return toTypeString(target) === '[object HTMLCanvasElement]'
}

export function isAnchorElement(target: unknown): target is HTMLAnchorElement {
return toTypeString(target) === '[object HTMLAnchorElement]'
}

export function isAudioElement(target: unknown): target is HTMLAnchorElement {
export function isAudioElement(target: unknown): target is HTMLAudioElement {
return toTypeString(target) === '[object HTMLAudioElement]'
}

export function isVideoElement(target: unknown): target is HTMLAnchorElement {
export function isVideoElement(target: unknown): target is HTMLVideoElement {
return toTypeString(target) === '[object HTMLVideoElement]'
}

Expand Down Expand Up @@ -777,10 +777,3 @@ export function formatEventType(type: string, appName: string): string {
export function isEmptyObject(target: unknown): boolean {
return isPlainObject(target) ? !Object.keys(target).length : true
}

/**
*
* @param {string} url input url
* @returns {boolean} is relative path
*/
export const isRelativePath = (url: string) => !/^https?:\/\//i.test(url) && !/^\/\//i.test(url)
2 changes: 2 additions & 0 deletions src/proxies/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ const WorkerProxy = new Proxy<Worker>(originalWorker, {

// @ts-ignore
window.Worker = WorkerProxy

export default WorkerProxy
11 changes: 3 additions & 8 deletions src/sandbox/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getPreventSetState,
throttleDeferForIframeAppName,
isAnchorElement,
isRelativePath,
isImageElement,
isVideoElement,
isAudioElement,
Expand Down Expand Up @@ -161,17 +160,13 @@ export function updateElementInfo <T> (node: T, appName: string | null): T {
// a 标签
const microApp = AppManager.getInstance().get(appName)
if (microApp) {
let originalHref = node.href
props.href = {
get() {
if (isRelativePath(originalHref)) {
return `${microApp.url}${originalHref}`
}
return originalHref
return this.getAttribute('href')
},
set(value: string) {
originalHref = value
}
this.setAttribute('href', value)
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/iframe/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function patchIframeAttribute (url: string, microAppWindow: microAppWindowType):
} else {
if (
((key === 'src' || key === 'srcset') && /^(img|script|video|audio|source|embed)$/i.test(this.tagName)) ||
(key === 'href' && /^(link|image)$/i.test(this.tagName))
(key === 'href' && /^(a|link|image)$/i.test(this.tagName))
) {
value = CompletionPath(value, url)
}
Expand Down
10 changes: 10 additions & 0 deletions src/sandbox/iframe/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
escape2RawWindowKeys,
escape2RawWindowRegExpKeys,
} from './special_key'
import WorkerProxy from '../../proxies/worker'

/**
* patch window of child app
Expand Down Expand Up @@ -153,6 +154,12 @@ function createProxyWindow (
const rawWindow = globalEnv.rawWindow
const customProperties = new Set<PropertyKey>()

Object.defineProperty(microAppWindow, 'Worker', {
value: WorkerProxy,
configurable: true,
writable: true,
})

/**
* proxyWindow will only take effect in certain scenes, such as window.key
* e.g:
Expand All @@ -162,6 +169,9 @@ function createProxyWindow (
*/
const proxyWindow = new Proxy(microAppWindow, {
get: (target: microAppWindowType, key: PropertyKey): unknown => {
if (key === 'Worker') {
return WorkerProxy
}
if (key === 'location') {
return sandbox.proxyLocation
}
Expand Down
4 changes: 2 additions & 2 deletions src/source/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function completePathDynamic (app: AppInterface, newChild: Node): void {
if (newChild.hasAttribute('srcset')) {
globalEnv.rawSetAttribute.call(newChild, 'srcset', CompletionPath(newChild.getAttribute('srcset')!, app.url))
}
} else if (/^(link|image)$/i.test(newChild.tagName) && newChild.hasAttribute('href')) {
} else if (/^(a|link|image)$/i.test(newChild.tagName) && newChild.hasAttribute('href')) {
globalEnv.rawSetAttribute.call(newChild, 'href', CompletionPath(newChild.getAttribute('href')!, app.url))
}
}
Expand Down Expand Up @@ -541,7 +541,7 @@ export function patchElementAndDocument (): void {
appInstanceMap.has(appName) &&
(
((key === 'src' || key === 'srcset') && /^(img|script|video|audio|source|embed)$/i.test(this.tagName)) ||
(key === 'href' && /^(link|image)$/i.test(this.tagName))
(key === 'href' && /^(a|link|image)$/i.test(this.tagName))
)
) {
const app = appInstanceMap.get(appName)
Expand Down

0 comments on commit e9be667

Please sign in to comment.