Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few more SSR problems #35165

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion js/src/dom/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function normalizeParams(originalTypeEvent, handler, delegationFn) {
}

function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
if (typeof originalTypeEvent !== 'string' || !element) {
if (typeof originalTypeEvent !== 'string' || !element || !element.addEventListener) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xvaara can you define the reason of this change?

return
}

Expand Down
13 changes: 8 additions & 5 deletions js/src/util/focustrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import EventHandler from '../dom/event-handler'
import SelectorEngine from '../dom/selector-engine'
import { typeCheckConfig } from './index'
import { typeCheckConfig, getDocument } from './index'

/**
* Constants
Expand Down Expand Up @@ -56,9 +56,11 @@ class FocusTrap {
trapElement.focus()
}

EventHandler.off(document, EVENT_KEY) // guard against infinite focus loop
EventHandler.on(document, EVENT_FOCUSIN, event => this._handleFocusin(event))
EventHandler.on(document, EVENT_KEYDOWN_TAB, event => this._handleKeydown(event))
const documentRef = getDocument()

EventHandler.off(documentRef, EVENT_KEY) // guard against infinite focus loop
EventHandler.on(documentRef, EVENT_FOCUSIN, event => this._handleFocusin(event))
EventHandler.on(documentRef, EVENT_KEYDOWN_TAB, event => this._handleKeydown(event))

this._isActive = true
}
Expand All @@ -76,8 +78,9 @@ class FocusTrap {
_handleFocusin(event) {
const { target } = event
const { trapElement } = this._config
const documentRef = getDocument()

if (target === document || target === trapElement || trapElement.contains(target)) {
if (target === documentRef || target === trapElement || trapElement.contains(target)) {
return
}

Expand Down
4 changes: 2 additions & 2 deletions js/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const reflow = element => {
}

const getjQuery = () => {
const { jQuery } = window
const { jQuery } = getWindow()

if (jQuery && !getDocument().body.hasAttribute('data-bs-no-jquery')) {
return jQuery
Expand Down Expand Up @@ -321,7 +321,7 @@ const getWindow = () => {
* @return {document|{}} The proper element
*/
const getDocument = () => {
return typeof document !== 'undefined' ? document : {}
return typeof document !== 'undefined' ? document : { documentElement: {} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xvaara can you define the reason of this change, too?

}

export {
Expand Down