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(perf): use classList.toggle instead of add/remove #8629

Merged
merged 8 commits into from
May 26, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* **breaking** Error on falsy values instead of stores passed to `derived` ([#7947](https://github.com/sveltejs/svelte/pull/7947))
* **breaking** Custom store implementers now need to pass an `update` function additionally to the `set` function ([#6750](https://github.com/sveltejs/svelte/pull/6750))
* **breaking** Change order in which preprocessors are applied ([#8618](https://github.com/sveltejs/svelte/pull/8618))
* **breaking** The runtime now makes use of `classList.toggle(name, boolean)` which does not work in very old browsers ([#8629](https://github.com/sveltejs/svelte/pull/8629))
* **breaking** apply `inert` to outroing elements ([#8627](https://github.com/sveltejs/svelte/pull/8627))
* Add a way to modify attributes for script/style preprocessors ([#8618](https://github.com/sveltejs/svelte/pull/8618))
* Improve hydration speed by adding `data-svelte-h` attribute to detect unchanged HTML elements ([#7426](https://github.com/sveltejs/svelte/pull/7426))
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/internal/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ export { ResizeObserverSingleton };
/**
* @returns {void} */
export function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
// The `!!` is required because an `undefined` flag means flipping the current state.
element.classList.toggle(name, !!toggle);
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down