fix(useTimeout): remove window prefix from setTimeout and clearTimeout for platform independence#333
Conversation
…learTimeout for platform-independent
There was a problem hiding this comment.
Pull request overview
This PR updates the core useTimeout hook to be platform-independent by avoiding window-scoped timer APIs, aligning with the project direction from issue #329.
Changes:
- Replace
window.setTimeout/window.clearTimeoutwith globalsetTimeout/clearTimeoutinuseTimeout. - Update the
useTimeoutJSDoc to remove thewindow.*reference. - Add a patch changeset for
react-simplikit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/core/src/hooks/useTimeout/useTimeout.ts |
Switches to global timer APIs and updates JSDoc for non-browser compatibility. |
.changeset/twelve-coats-end.md |
Adds a patch release note for the platform-independence fix. |
You can also share your feedback on Copilot code review. Take the survey.
| * @description | ||
| * `useTimeout` is a React hook that executes a callback function after a specified delay. | ||
| * It manages `window.setTimeout` in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change. | ||
| * It manages `setTimeout` in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change. |
There was a problem hiding this comment.
The markdown docs for this hook still mention window.setTimeout (see packages/core/src/hooks/useTimeout/useTimeout.md), which conflicts with the new platform-independent implementation. Please update the docs in the same PR so user-facing documentation stays accurate.
| * It manages `setTimeout` in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change. | |
| * It schedules the callback with a timer in accordance with the React lifecycle, ensuring cleanup on unmount or when dependencies change. |
| 'react-simplikit': patch | ||
| --- | ||
|
|
||
| remove window prefix from setTimeout and clearTimeout for platform-independent |
There was a problem hiding this comment.
Changeset summary is a bit ungrammatical and reads like it’s missing a noun at the end ("for platform-independent"). Consider rewording to a complete sentence (and typically capitalizing/ending with a period) since this text is user-facing in release notes.
| remove window prefix from setTimeout and clearTimeout for platform-independent | |
| Remove window prefix from setTimeout and clearTimeout for platform-independent behavior. |
kimyouknow
left a comment
There was a problem hiding this comment.
LGTM! — we'll merge once CI passes. ✅
Overview
Replace
window.setTimeoutandwindow.clearTimeoutwith the globalsetTimeoutandclearTimeoutto align with the project's platform-independent direction introduced in #329window.setTimeoutonly works in browser environments, causing issues in SSR (Next.js), React Native, and other non-browser JavaScript environments.Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?