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. ); }