Throttle replace state in restore scroll (#16693)

This commit is contained in:
Bram Kragten 2023-05-31 14:18:48 +02:00 committed by GitHub
parent 9b896c63b6
commit 2219c9bbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,10 @@
import type { LitElement } from "lit";
import type { ClassElement } from "../../types";
import { throttle } from "../util/throttle";
const throttleReplaceState = throttle((value) => {
history.replaceState({ scrollPosition: value }, "");
}, 300);
export const restoreScroll =
(selector: string): any =>
@ -9,7 +14,7 @@ export const restoreScroll =
key: element.key,
descriptor: {
set(this: LitElement, value: number) {
history.replaceState({ scrollPosition: value }, "");
throttleReplaceState(value);
this[`__${String(element.key)}`] = value;
},
get(this: LitElement) {