Skip to content

Commit

Permalink
fix: fix bug of element-plus dom escape from micro-app element
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed Jan 9, 2022
1 parent 5050cfd commit c6120e8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dev/children/react16/config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ module.exports = function (proxy, allowedHost) {
},
public: allowedHost,
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
proxy,
proxy: {
'/sugrec': {
target: 'https://www.baidu.com',
secure: false,
changeOrigin: true,
}
},
before(app, server) {
// Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
// middlewares before `redirectServedPath` otherwise will not have any effect
Expand Down
8 changes: 8 additions & 0 deletions dev/children/react16/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ if (window.__MICRO_APP_ENVIRONMENT__) {
// requestAnimationFrame(() => {
// console.log(444444)
// })

// ----------------------分割线--接口相关--------------------- //
// 测试proxy代理
fetch('http://localhost:3001/sugrec').then((res) => {
return res.json()
}).then((data) => {
console.log('proxy代理 https://www.baidu.com/sugrec 返回数据', data)
})
2 changes: 1 addition & 1 deletion dev/main-react16/src/pages/vue3/vue3.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Vue3 () {
onMounted={() => hideLoading(false)}
onBeforeshow={() => hideLoading(false)}
baseRoute='/micro-app/demo/vue3'
disableScopecss
// disableScopecss
// keep-alive
// inline
// destroy
Expand Down
25 changes: 23 additions & 2 deletions src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class SandBox implements SandBoxInterface {
// get scopeProperties and escapeProperties from plugins
this.getScopeProperties(appName)
// create proxyWindow with Proxy(microAppWindow)
this.proxyWindow = this.createProxyWindow()
this.proxyWindow = this.createProxyWindow(appName)
// inject global properties
this.initMicroAppWindow(this.microAppWindow, appName, url)
// Rewrite global event listener & timeout
Expand Down Expand Up @@ -174,12 +174,13 @@ export default class SandBox implements SandBoxInterface {
}

// create proxyWindow with Proxy(microAppWindow)
private createProxyWindow () {
private createProxyWindow (appName: string) {
const rawWindow = globalEnv.rawWindow
const descriptorTargetMap = new Map<PropertyKey, 'target' | 'rawWindow'>()
// window.xxx will trigger proxy
return new Proxy(this.microAppWindow, {
get: (target: microAppWindowType, key: PropertyKey): unknown => {
throttleDeferForSetAppName(appName)
if (
Reflect.has(target, key) ||
(isString(key) && /^__MICRO_APP_/.test(key)) ||
Expand Down Expand Up @@ -291,6 +292,26 @@ export default class SandBox implements SandBoxInterface {
microAppWindow.rawDocument = globalEnv.rawDocument
microAppWindow.removeDomScope = removeDomScope
microAppWindow.hasOwnProperty = (key: PropertyKey) => rawHasOwnProperty.call(microAppWindow, key) || rawHasOwnProperty.call(globalEnv.rawWindow, key)
// rawDefineProperty(microAppWindow, Symbol.unscopables, {
// get () {
// throttleDeferForSetAppName(appName)
// return {}
// },
// configurable: true,
// enumerable: false,
// })

// let ngDevMode: any = null
// rawDefineProperty(microAppWindow, 'ngDevMode', {
// get () {
// return ngDevMode || globalEnv.rawWindow.ngDevMode
// },
// set (value) {
// ngDevMode = value
// },
// configurable: true,
// enumerable: true,
// })
this.setMappingPropertiesWithRawDescriptor(microAppWindow)
this.setHijackProperties(microAppWindow, appName)
}
Expand Down

0 comments on commit c6120e8

Please sign in to comment.