Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/sandbox/with/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export function patchWindow (
microAppWindow: microAppWindowType,
sandbox: WithSandBoxInterface,
): CommonEffectHook {
const descriptorTargetMap = new Map<PropertyKey, 'target' | 'rawWindow'>()
patchWindowProperty(microAppWindow)
createProxyWindow(appName, microAppWindow, sandbox)
return patchWindowEffect(microAppWindow, appName)
createProxyWindow(appName, microAppWindow, sandbox, descriptorTargetMap)
return patchWindowEffect(microAppWindow, appName, descriptorTargetMap)
}

/**
Expand Down Expand Up @@ -84,9 +85,9 @@ function createProxyWindow (
appName: string,
microAppWindow: microAppWindowType,
sandbox: WithSandBoxInterface,
descriptorTargetMap: Map<PropertyKey, 'target' | 'rawWindow'>,
): void {
const rawWindow = globalEnv.rawWindow
const descriptorTargetMap = new Map<PropertyKey, 'target' | 'rawWindow'>()

rawDefineProperty(microAppWindow, 'Worker', {
value: WorkerProxy,
Expand Down Expand Up @@ -219,7 +220,11 @@ function createProxyWindow (
* Rewrite side-effect events
* @param microAppWindow micro window
*/
function patchWindowEffect (microAppWindow: microAppWindowType, appName: string): CommonEffectHook {
function patchWindowEffect (
microAppWindow: microAppWindowType,
appName: string,
descriptorTargetMap: Map<PropertyKey, 'target' | 'rawWindow'>,
): CommonEffectHook {
const eventListenerMap = new Map<string, Set<MicroEventListener>>()
const sstEventListenerMap = new Map<string, Set<MicroEventListener>>()
const intervalIdMap = new Map<number, timeInfo>()
Expand Down Expand Up @@ -387,6 +392,9 @@ function patchWindowEffect (microAppWindow: microAppWindowType, appName: string)
intervalIdMap.clear()
timeoutIdMap.clear()
}

// clear descriptor target cache to avoid unbounded growth on repeated mount/unmount
descriptorTargetMap.clear()
}

return {
Expand Down