From 3b74fc16b0108dd8bdcafb7b795d8203ba2ba756 Mon Sep 17 00:00:00 2001 From: will-selfactualize Date: Tue, 1 Dec 2026 16:27:17 -0800 Subject: [PATCH] Reproducer for #60450: timeOrigin + now() lags Date.now() by sleep on iOS Shows Date.now() - (performance.timeOrigin + performance.now()) in the Playground, refreshed every second. On iOS/macOS it jumps by the sleep duration after the device or host Mac sleeps; it should stay ~0. Co-Authored-By: Claude Opus 5.5 --- .../examples/Playground/RNTesterPlayground.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js index 8e6b10479de7..7143f769bc96 100644 --- a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js +++ b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js @@ -12,14 +12,33 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import RNTesterText from '../../components/RNTesterText'; import * as React from 'react'; +import {useEffect, useState} from 'react'; import {StyleSheet, View} from 'react-native'; +// Reproducer for #60450: on iOS/macOS, performance.timeOrigin + performance.now() +// should approximate Date.now(), but it lags by the device's total sleep since +// boot. Run on an iOS simulator after the host Mac has slept (or on a device +// after it has slept), or leave this screen open and put the Mac to sleep for a +// minute: the drift jumps by the sleep duration. On Android it stays ~0. +function readDriftMs(): number { + return Date.now() - (performance.timeOrigin + performance.now()); +} + function Playground() { + const [driftMs, setDriftMs] = useState(readDriftMs); + + useEffect(() => { + const id = setInterval(() => setDriftMs(readDriftMs()), 1000); + return () => clearInterval(id); + }, []); + return ( - - Edit "RNTesterPlayground.js" to change this file + + Date.now() - (performance.timeOrigin + performance.now()) ={' '} + {(driftMs / 1000).toFixed(3)} s + Expected: about 0 s on every platform. ); }