Skip to content

fix(useInterval): remove window prefix from setInterval and clearInterval for platform independence#345

Merged
kimyouknow merged 5 commits intotoss:mainfrom
eunwoo-levi:fix/fix-useInterval-platform-independence
Mar 18, 2026
Merged

fix(useInterval): remove window prefix from setInterval and clearInterval for platform independence#345
kimyouknow merged 5 commits intotoss:mainfrom
eunwoo-levi:fix/fix-useInterval-platform-independence

Conversation

@eunwoo-levi
Copy link
Contributor

Overview

Problem

useInterval used window.setInterval and window.clearInterval, which are browser-only APIs.
This breaks in non-browser environments like React Native and SSR.

Solution

Replace window.setInterval / window.clearInterval with the global setInterval /
clearInterval.

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?

…rval for platform independence

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Clean fix, consistent with #333 (useTimeout). We'll merge #347 first since it also touches useInterval.ts, then this PR will need a quick rebase.

Could you also add a changeset? (yarn changeset — patch level)

Copilot AI review requested due to automatic review settings March 18, 2026 01:31
@eunwoo-levi
Copy link
Contributor Author

@kimyouknow Added a patch changeset! Thanks for the review:)

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 useInterval hook in packages/core to avoid browser-only window.* timer APIs so it works in non-browser environments (e.g., React Native, SSR).

Changes:

  • Replace window.setInterval / window.clearInterval with global setInterval / clearInterval in useInterval.
  • Add a patch changeset documenting the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/hooks/useInterval/useInterval.ts Removes window.* timer usage to make the hook platform-independent.
.changeset/silly-pumas-swim.md Adds release-note entry for the timer API change.

'react-simplikit': patch
---

fix useInterval to use globalThis instead of window for platform independence
@eunwoo-levi eunwoo-levi requested a review from kimyouknow March 18, 2026 01:33
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!

@kimyouknow kimyouknow merged commit 35d13f8 into toss:main Mar 18, 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