From 2219c9bbd347ca1da71073800cf9af9852c9e199 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 31 May 2023 14:18:48 +0200 Subject: [PATCH] Throttle replace state in restore scroll (#16693) --- src/common/decorators/restore-scroll.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/decorators/restore-scroll.ts b/src/common/decorators/restore-scroll.ts index ff427cf33e..b7ba120cf5 100644 --- a/src/common/decorators/restore-scroll.ts +++ b/src/common/decorators/restore-scroll.ts @@ -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) {