Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions packages/renderless/src/common/deps/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { hasOwn, isObject, isNull } from '../type'
import globalConfig from '../global'

const isServer = typeof window === 'undefined'
const SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g
Expand Down Expand Up @@ -225,8 +226,9 @@ export const isVNode = (node: any) => node !== null && isObject(node) && hasOwn.
* @returns visibleWidth : 可视区宽度(不含滚动条)
*/
export const getDomNode = () => {
let documentElement = document.documentElement
let bodyElem = document.body
const viewportWindow = globalConfig.viewportWindow || window
let documentElement = viewportWindow.document.documentElement
let bodyElem = viewportWindow.document.body

return {
scrollTop: documentElement.scrollTop || bodyElem.scrollTop,
Expand Down
4 changes: 3 additions & 1 deletion packages/renderless/src/common/deps/popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { on, off } from './dom'
import PopupManager from './popup-manager'
import globalConfig from '../global'
import { typeOf } from '../type'

const positions = ['left', 'right', 'top', 'bottom']
Expand Down Expand Up @@ -752,7 +753,8 @@ class Popper {
let scrollTop = isFixed ? 0 : getScrollTopValue(scrollParent)
let scrollLeft = isFixed ? 0 : getScrollLeftValue(scrollParent)

const viewportWindow = PopupManager.viewportWindow || window
// PopupManager.viewportWindow是为了兼容之前已经采用此方法兼容微前端的用户,后续需要采用globalConfig.viewportWindow
const viewportWindow = globalConfig.viewportWindow || PopupManager.viewportWindow || window
boundaries = {
top: 0 - (offsetParentRect.top - scrollTop),
right: viewportWindow.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft),
Expand Down
5 changes: 5 additions & 0 deletions packages/renderless/src/common/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const globalConfig = {
viewportWindow: null // 获取真实视口的window,解决在微前端中某些bug
}

export default globalConfig