Skip to content

Commit

Permalink
fix: fix bug of scopeproperties & keep-alive app for memory-router
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed Sep 9, 2022
1 parent a4636c0 commit 7d60f6d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
14 changes: 14 additions & 0 deletions dev/children/react16/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
// import './public-path';
// import 'babel-polyfill'
// import '@babel/polyfill'
Expand Down Expand Up @@ -285,6 +286,19 @@ window.escapeKey5 = 'escapeKey5' // should be undefined in rawWindow
window.escapeKey6 = 'escapeKey6' // should be undefined in rawWindow


console.log('scopeProperties scopeKeySpe: ', scopeKeySpe)
console.log('scopeProperties window.scopeKeySpe: ', window.scopeKeySpe)

console.log('scopeProperties Vue: ', Vue)
console.log('scopeProperties window.Vue: ', window.Vue)

window.Vue = Vue ? Vue : 'child Vue'

console.log('scopeProperties Vue: ', Vue)
console.log('scopeProperties window.Vue: ', window.Vue)



/* ---------------------- pureCreateElement & removeDomScope --------------------- */
if (window.__MICRO_APP_ENVIRONMENT__) {
const unBoundDom1 = window.microApp.pureCreateElement('div')
Expand Down
5 changes: 4 additions & 1 deletion dev/main-react16/src/global.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const prefetchConfig = [

// microApp.preFetch(prefetchConfig)

window['scopeKeySpe'] = 'value from base app'
window.Vue = 'Vue from base'

microApp.start({
// shadowDOM: true,
// inline: true,
Expand Down Expand Up @@ -95,7 +98,7 @@ microApp.start({
plugins: {
global: [
{
scopeProperties: ['scopeKey1', 'scopeKey2'],
scopeProperties: ['scopeKey1', 'scopeKey2', 'scopeKeySpe'],
escapeProperties: ['escapeKey1', 'escapeKey2'],
options: {a: 1,},
loader(code, url, options) {
Expand Down
2 changes: 1 addition & 1 deletion dev/main-react16/src/pages/react16/react16.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default class App extends React.Component {
onAfterhidden={this.handleAfterhidden}
onDataChange={this.handleDataChange}
baseroute='/micro-app/demo/react16'
keep-alive
// keep-alive
// destroy
// inline
// disableSandbox
Expand Down
2 changes: 2 additions & 0 deletions docs/1.x/zh-cn/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- 🐞 修复了angular框架下,micro-app设置动态url导致应用多次渲染的问题。
- 🐞 修复了子应用title、meta元素丢失的问题。
- 🐞 修复了部分场景下`scopeProperties`可以逃逸的问题。
- 🐞 修复了关闭虚拟路由系统时keep-alive应用依然可以触发虚拟路由系统的问题。

- **Update**

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-alpha.8",
"version": "1.0.0-alpha.9",
"description": "A lightweight, efficient and powerful micro front-end framework",
"private": false,
"main": "lib/index.min.js",
Expand Down
12 changes: 8 additions & 4 deletions src/create_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,10 @@ export default class CreateApp implements AppInterface {
lifeCycles.AFTERHIDDEN,
)

// called after lifeCyclesEvent
this.sandBox?.removeRouteInfoForKeepAliveApp()
if (this.useMemoryRouter) {
// called after lifeCyclesEvent
this.sandBox?.removeRouteInfoForKeepAliveApp()
}

this.recordAndReleaseEffect()

Expand Down Expand Up @@ -587,8 +589,10 @@ export default class CreateApp implements AppInterface {

this.keepAliveState = keepAliveStates.KEEP_ALIVE_SHOW

// called before lifeCyclesEvent
this.sandBox?.setRouteInfoForKeepAliveApp()
if (this.useMemoryRouter) {
// called before lifeCyclesEvent
this.sandBox?.setRouteInfoForKeepAliveApp()
}

// dispatch afterShow event to micro-app
dispatchCustomEventToMicroApp('appstate-change', this.name, {
Expand Down
20 changes: 18 additions & 2 deletions src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ export default class SandBox implements SandBoxInterface {
}

/**
* 1. prevent the key deleted during sandBox.stop after rewrite
* 2. umd mode will not delete any keys during sandBox.stop
* 1. Prevent the key deleted during sandBox.stop after rewrite
* 2. Umd mode will not delete any keys during sandBox.stop
* 3. It must not be umd mode when call sandbox.start at the first time
*/
if (!umdMode) {
this.initGlobalKeysWhenStart(
Expand Down Expand Up @@ -443,6 +444,7 @@ export default class SandBox implements SandBoxInterface {
pureCreateElement,
router,
})

this.setProxyDocument(microAppWindow, appName)
this.setMappingPropertiesWithRawDescriptor(microAppWindow)
}
Expand Down Expand Up @@ -529,6 +531,7 @@ export default class SandBox implements SandBoxInterface {
microAppWindow.hasOwnProperty = (key: PropertyKey) => rawHasOwnProperty.call(microAppWindow, key) || rawHasOwnProperty.call(globalEnv.rawWindow, key)
this.setHijackProperty(microAppWindow, appName)
if (!disablePatchRequest) this.patchRequestApi(microAppWindow, appName, url)
this.setScopeProperties(microAppWindow)
}

// set hijack Properties to microAppWindow
Expand Down Expand Up @@ -600,6 +603,19 @@ export default class SandBox implements SandBoxInterface {
})
}

/**
* Init scope keys to microAppWindow, prevent fall to rawWindow from with(microAppWindow)
* like: if (!xxx) {}
* NOTE:
* 1. Symbol.unscopables cannot affect undefined keys
* 2. Doesn't use for window.xxx because it fall to proxyWindow
*/
setScopeProperties (microAppWindow: microAppWindowType): void {
this.scopeProperties.forEach((key: PropertyKey) => {
Reflect.set(microAppWindow, key, microAppWindow[key])
})
}

// set location & history for memory router
private setMicroAppRouter (microAppWindow: microAppWindowType, appName: string, url: string): void {
const { microLocation, microHistory } = createMicroRouter(appName, url)
Expand Down

0 comments on commit 7d60f6d

Please sign in to comment.