✨port document.querySelector('head') to qiankun head in micro app (#2499)
This commit is contained in:
parent
bf01881c97
commit
a8f5b766f8
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
import type { Freer, SandBox } from '../../../interfaces';
|
||||
import { isBoundedFunction, nativeDocument, nativeGlobal, isCallable } from '../../../utils';
|
||||
import { isBoundedFunction, isCallable, nativeDocument, nativeGlobal } from '../../../utils';
|
||||
import { getCurrentRunningApp } from '../../common';
|
||||
import type { ContainerConfig } from './common';
|
||||
import {
|
||||
|
|
@ -67,7 +67,8 @@ function patchDocument(cfg: { sandbox: SandBox; speedy: boolean }) {
|
|||
return true;
|
||||
},
|
||||
get: (target, p, receiver) => {
|
||||
if (p === 'createElement') {
|
||||
switch (p) {
|
||||
case 'createElement': {
|
||||
// Must store the original createElement function to avoid error in nested sandbox
|
||||
const targetCreateElement = target.createElement;
|
||||
return function createElement(...args: Parameters<typeof document.createElement>) {
|
||||
|
|
@ -87,6 +88,27 @@ function patchDocument(cfg: { sandbox: SandBox; speedy: boolean }) {
|
|||
};
|
||||
}
|
||||
|
||||
case 'querySelector': {
|
||||
const targetQuerySelector = target.querySelector;
|
||||
return function querySelector(...args: Parameters<typeof document.querySelector>) {
|
||||
const selector = args[0];
|
||||
switch (selector) {
|
||||
case 'head': {
|
||||
const containerConfig = proxyAttachContainerConfigMap.get(sandbox.proxy);
|
||||
if (containerConfig) {
|
||||
return getAppWrapperHeadElement(containerConfig.appWrapperGetter());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return targetQuerySelector.call(target, ...args);
|
||||
};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const value = (<any>target)[p];
|
||||
// must rebind the function to the target otherwise it will cause illegal invocation error
|
||||
if (isCallable(value) && !isBoundedFunction(value)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user