Skip to content

Commit

Permalink
perf: disable toggling <body> CSS class by default
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-vuong-holistics committed Jul 29, 2024
1 parent 99e1452 commit b77c27b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v5.2.2-holistics.1

### 🚀 Performance Improvements

- Disable toggle `<body>` CSS class by default to avoid performance overhead. Can be re-enabled via `toggleBodyClass` prop. ([PR #1019](https://github.com/Akryum/floating-vue/pull/1019))

### ❤️ Contributors

- Cuong Vuong ([@cuong-vuong-holistics](https://github.com/cuong-vuong-holistics))

## v5.2.2


Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## About the fork

This fork has the `@holistics/floating-vue` package that tries to fix some issues of the original package.
This fork has the `@holistics/floating-vue` package that tries to fix the following issues:

- **[Performance]** Disable toggling CSS class of `<body>`: this makes the entire page reflow whenever some floating elements are shown/all are hidden ([PR #1019](https://github.com/Akryum/floating-vue/pull/1019)). Can be re-enabled via `toggleBodyClass` prop.

### 📦️ Versioning and syncing

Expand Down
4 changes: 3 additions & 1 deletion packages/floating-vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## About the fork

This fork has the `@holistics/floating-vue` package that tries to fix some issues of the original package.
This fork has the `@holistics/floating-vue` package that tries to fix the following issues:

- **[Performance]** Disable toggling CSS class of `<body>`: this makes the entire page reflow whenever some floating elements are shown/all are hidden ([PR #1019](https://github.com/Akryum/floating-vue/pull/1019)). Can be re-enabled via `toggleBodyClass` prop.

### 📦️ Versioning and syncing

Expand Down
2 changes: 1 addition & 1 deletion packages/floating-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holistics/floating-vue",
"version": "5.2.2-holistics.0",
"version": "5.2.2-holistics.1",
"description": "Holistics fork of Floating Vue - Easy Vue tooltips, dropdowns, menus & popovers using floating-ui",
"contributors": [
"Guillaume Chau <guillaume.b.chau@gmail.com>",
Expand Down
33 changes: 21 additions & 12 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ const createPopper = () => defineComponent({
type: Number,
default: defaultPropFactory('disposeTimeout'),
},

toggleBodyClass: {
type: Boolean,
default: undefined,
},
},

emits: {
Expand Down Expand Up @@ -773,10 +778,12 @@ const createPopper = () => defineComponent({
}

shownPoppers.push(this)
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.toggleBodyClass) {
this.toggleBodyClass && 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}`)
}
}

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

this.skipTransition = skipTransition
removeFromArray(shownPoppers, this)
if (shownPoppers.length === 0) {
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) {
document.body.classList.remove(`v-popper--some-open--${theme}`)
if (this.toggleBodyClass) {
if (shownPoppers.length === 0) {
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) {
document.body.classList.remove(`v-popper--some-open--${theme}`)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/floating-vue/src/components/PopperWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ export default defineComponent({
type: Number,
default: undefined,
},
toggleBodyClass: {
type: Boolean,
default: undefined,
},
},
emits: {
Expand Down

0 comments on commit b77c27b

Please sign in to comment.