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

Performance issue due to adding popper classes to body on page with large number of DOM nodes #1019

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 14 additions & 4 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ const createPopper = () => defineComponent({
default: defaultPropFactory('computeTransformOrigin'),
},

addPopperClassesToBody: {
type: Boolean,
default: defaultPropFactory('addPopperClassesToBody'),
},

/**
* @deprecated
*/
Expand Down Expand Up @@ -773,10 +778,15 @@ const createPopper = () => defineComponent({
}

shownPoppers.push(this)
document.body.classList.add('v-popper--some-open')
if (this.addPopperClassesToBody) {
document.body.classList.add('v-popper--some-open')
}

for (const theme of getAllParentThemes(this.theme)) {
getShownPoppersByTheme(theme).push(this)
document.body.classList.add(`v-popper--some-open--${theme}`)
if (this.addPopperClassesToBody) {
document.body.classList.add(`v-popper--some-open--${theme}`)
}
}

this.$emit('apply-show')
Expand Down Expand Up @@ -807,13 +817,13 @@ const createPopper = () => defineComponent({

this.skipTransition = skipTransition
removeFromArray(shownPoppers, this)
if (shownPoppers.length === 0) {
if (shownPoppers.length === 0 && this.addPopperClassesToBody) {
document.body.classList.remove('v-popper--some-open')
}
for (const theme of getAllParentThemes(this.theme)) {
const list = getShownPoppersByTheme(theme)
removeFromArray(list, this)
if (list.length === 0) {
if (list.length === 0 && this.addPopperClassesToBody) {
document.body.classList.remove(`v-popper--some-open--${theme}`)
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/floating-vue/src/components/PopperWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ export default defineComponent({
default: undefined,
},

addPopperClassesToBody: {
type: Boolean,
default: true,
},


/**
* @deprecated
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/floating-vue/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const config: FloatingVueConfig = {
arrowPadding: 0,
// Compute arrow overflow (useful to hide it)
arrowOverflow: true,
// Add popper classes to body, allowing more customization but may affect performance
addPopperClassesToBody: true,
// Themes
themes: {
tooltip: {
Expand Down