Skip to content

Commit

Permalink
fix(1.0.0-beta.5): fix bug of __MICRO_APP_BASE_APPLICATION__ is undef…
Browse files Browse the repository at this point in the history
…ined
  • Loading branch information
bailicangdu committed May 19, 2023
1 parent 66f7c95 commit cafe520
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
15 changes: 11 additions & 4 deletions dev/main-react16/src/pages/react16/react16.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,17 @@ export default class App extends React.Component {
}

changeNameUrl = () => {
this.setState({
name: 'react16',
url: `${config.react16}micro-app/react16/?a=2`,
})
if (this.state.name === 'vue2-change') {
this.setState({
name: 'react16',
url: `${config.react16}micro-app/react16/?a=1`,
})
} else {
this.setState({
name: 'vue2-change',
url: `${config.vue2}micro-app/vue2/`,
})
}
}

// 主动卸载应用
Expand Down
13 changes: 13 additions & 0 deletions docs/1.x/zh-cn/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

---

### 1.0.0-beta.5

`2023-05-25`

- **Bug Fix**

- 🐞 修复了环境变量`__MICRO_APP_BASE_APPLICATION__`为undefined的问题。

- **Update**

- 🚀 优化了部分开发案例。


### 1.0.0-beta.4

`2023-04-27`
Expand Down
10 changes: 10 additions & 0 deletions src/create_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ export default class CreateApp implements AppInterface {
this.sandBox?.removeRouteInfoForKeepAliveApp()
}

/**
* TODO: 果然不行,遇到bug了,因为micro-app被隐藏还有另外一种情况,通过修改url和name
* micro-app元素没有被删除,而新的应用开始使用micro-app元素,两者同用一个元素,肯定会出问题
*/
this.container = cloneContainer(
pureCreateElement('micro-app'),
this.container as Element,
false,
)

this.sandBox?.recordAndReleaseEffect({ keepAlive: true })

callback?.()
Expand Down
5 changes: 3 additions & 2 deletions src/libs/global_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ declare global {
}

const globalEnv: Record<string, any> = {
// mark current application as base application
__MICRO_APP_BASE_APPLICATION__: true,
// active sandbox count
activeSandbox: 0,
}
Expand Down Expand Up @@ -121,6 +119,9 @@ export function initGlobalEnv (): void {
const rawAddEventListener = rawRootEventTarget.prototype.addEventListener
const rawRemoveEventListener = rawRootEventTarget.prototype.removeEventListener

// mark current application as base application
window.__MICRO_APP_BASE_APPLICATION__ = true

assign(globalEnv, {
supportModuleScript: isSupportModuleScript(),

Expand Down
3 changes: 2 additions & 1 deletion src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
MicroLocation,
AttrsType,
fiberTasks,
MicroAppElementTagNameMap,
} from '@micro-app/types'

export const version = '__MICRO_APP_VERSION__'
Expand Down Expand Up @@ -414,7 +415,7 @@ export function isSafari (): boolean {
/**
* Create pure elements
*/
export function pureCreateElement<K extends keyof HTMLElementTagNameMap> (tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K] {
export function pureCreateElement<K extends keyof MicroAppElementTagNameMap> (tagName: K, options?: ElementCreationOptions): MicroAppElementTagNameMap[K] {
const element = document.createElement(tagName, options)
if (element.__MICRO_APP_NAME__) delete element.__MICRO_APP_NAME__
element.__PURE_ELEMENT__ = true
Expand Down
4 changes: 4 additions & 0 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ declare module '@micro-app/types' {
args: any[],
}

interface MicroAppElementTagNameMap extends HTMLElementTagNameMap {
'micro-app': any,
}

interface CommonEffectHook {
reset(): void
record(): void
Expand Down

0 comments on commit cafe520

Please sign in to comment.