Skip to content

fix(useTimeout): remove window prefix from setTimeout and clearTimeout for platform independence#333

Merged
kimyouknow merged 3 commits intotoss:mainfrom
dlsxjzld:fix/fix-useTimeout
Mar 13, 2026
Merged

fix(useTimeout): remove window prefix from setTimeout and clearTimeout for platform independence#333
kimyouknow merged 3 commits intotoss:mainfrom
dlsxjzld:fix/fix-useTimeout

Conversation

@dlsxjzld
Copy link
Contributor

@dlsxjzld dlsxjzld commented Mar 5, 2026

Overview

Replace window.setTimeout and window.clearTimeout with the global setTimeout and clearTimeout to align with the project's platform-independent direction introduced in #329

window.setTimeout only works in browser environments, causing issues in SSR (Next.js), React Native, and other non-browser JavaScript environments.

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

Copilot AI review requested due to automatic review settings March 5, 2026 11:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.clearTimeout with global setTimeout / clearTimeout in useTimeout.
  • Update the useTimeout JSDoc to remove the window.* 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.
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
'react-simplikit': patch
---

remove window prefix from setTimeout and clearTimeout for platform-independent
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
remove window prefix from setTimeout and clearTimeout for platform-independent
Remove window prefix from setTimeout and clearTimeout for platform-independent behavior.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@kimyouknow kimyouknow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! — we'll merge once CI passes. ✅

@kimyouknow kimyouknow merged commit 4254542 into toss:main Mar 13, 2026
11 checks passed
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.

3 participants