Skip to content

Commit

Permalink
fix: 修复nuxt启动报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zzcr committed Dec 11, 2024
1 parent 6791cf8 commit 7a62b83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/renderless/src/common/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const isEdge = (browser) => {
export const isBrowser =
typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document

export const globalEnvironment =
typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document ? window : global
export const globalEnvironment = isBrowser ? window : global

export default (() => {
const browser = {
Expand Down
10 changes: 5 additions & 5 deletions packages/renderless/src/common/deps/fullscreen/screenfull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const screenfull = {

this.on('change', onFullscreenEntered)

element = element || (typeof document !== 'undefined' ? document.documentElement : null)
element = element || (isBrowser ? document.documentElement : null)

if (element && fullscreenEvents && element[fullscreenEvents.requestFullscreen]) {
const promiseReturn = element[fullscreenEvents.requestFullscreen](options)
Expand All @@ -117,7 +117,7 @@ const screenfull = {

this.on('change', onFullscreenExit)

if (typeof document !== 'undefined' && fullscreenEvents && document[fullscreenEvents.exitFullscreen]) {
if (isBrowser && fullscreenEvents && document[fullscreenEvents.exitFullscreen]) {
const promiseReturn = document[fullscreenEvents.exitFullscreen]()

if (promiseReturn instanceof Promise) {
Expand All @@ -140,22 +140,22 @@ const screenfull = {
on(event, callback) {
const eventName = eventNameMap[event]

if (eventName && typeof document !== 'undefined') {
if (eventName && isBrowser) {
on(document, eventName, callback)
}
},
off(event, callback) {
const eventName = eventNameMap[event]

if (eventName && typeof document !== 'undefined') {
if (eventName && isBrowser) {
off(document, eventName, callback)
}
},
raw: fullscreenEvents || {}
}

// 处理屏幕全屏状态的方法
if (typeof document !== 'undefined') {
if (isBrowser) {
Object.defineProperties(screenfull, {
isFullscreen: {
get() {
Expand Down

0 comments on commit 7a62b83

Please sign in to comment.