Skip to content

Read the clock outside render in the purity example - #8778

Open
git-abhijeet wants to merge 1 commit into
reactjs:mainfrom
git-abhijeet:fix/clock-render-purity
Open

git-abhijeet wants to merge 1 commit into
reactjs:mainfrom
git-abhijeet:fix/clock-render-purity

Conversation

@git-abhijeet

Copy link
Copy Markdown

Fixes #8777.

The clock example said it only read the current time outside render, but its state initializer still called new Date() during render. The example now displays “Loading…” until the first interval tick supplies a time. The interval continues to update the clock every second.

I ran the example extracted from the page with React DOM. Before the change, server rendering read the clock once. After the change, server rendering and hydration made zero clock reads, two successive ticks updated the displayed time, and unmounting cleared the interval.

The repository’s yarn ci-check also passed on Node 24.

@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

This branch was successfully deployed

1 active deployment
Preview — 490dfafa Deployed Nov 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Components and Hooks must be pure: the useTime example still runs new Date() during render

1 participant