From 0b2270d4170f956ebdc848290b66d7b1b34d31d7 Mon Sep 17 00:00:00 2001 From: MaYuanhai <414199639@qq.com> Date: Wed, 18 Jun 2025 22:28:05 +0800 Subject: [PATCH] Update events.ts Resolve the issue of automatic system time updates causing registered listeners to become invalid When the system automatically updates the time to the time before assigning the value to 'invoker. attached', 'e.vts<=invoker. attached' will cause the function to always jump out, resulting in listening failure --- packages/runtime-dom/src/modules/events.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/runtime-dom/src/modules/events.ts b/packages/runtime-dom/src/modules/events.ts index 600b0840c..9703e18a1 100644 --- a/packages/runtime-dom/src/modules/events.ts +++ b/packages/runtime-dom/src/modules/events.ts @@ -83,12 +83,12 @@ function parseName(name: string): [string, EventListenerOptions | undefined] { return [event, options] } -// To avoid the overhead of repeatedly calling Date.now(), we cache +// To avoid the overhead of repeatedly calling performance.now(), we cache // and use the same timestamp for all event listeners attached in the same tick. let cachedNow: number = 0 const p = /*@__PURE__*/ Promise.resolve() const getNow = () => - cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now())) + cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = performance.now())) function createInvoker( initialValue: EventValue, @@ -108,7 +108,7 @@ function createInvoker( // The handler would only fire if the event passed to it was fired // AFTER it was attached. if (!e._vts) { - e._vts = Date.now() + e._vts = performance.now() } else if (e._vts <= invoker.attached) { return }