Skip to content

fix(webapp): clear overlapping timeouts and reset useCopy hook state on value change#4036

Closed
HarshalPatel1972 wants to merge 1 commit into
triggerdotdev:mainfrom
HarshalPatel1972:fix/copy-button-timeout
Closed

fix(webapp): clear overlapping timeouts and reset useCopy hook state on value change#4036
HarshalPatel1972 wants to merge 1 commit into
triggerdotdev:mainfrom
HarshalPatel1972:fix/copy-button-timeout

Conversation

@HarshalPatel1972

@HarshalPatel1972 HarshalPatel1972 commented Jun 25, 2026

Copy link
Copy Markdown

Closes #4036

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  • Verified by executing local event sequences on the CopyButton primitive. Confirmed that making rapid, successive clicks cleanly evicts previous macro-task timer registrations from the event loop using the useRef pointer.
  • Verified state alignment by mutating the incoming value prop during an active copied === true state window, confirming that the button cleanly reverts back to the copy icon via the new useEffect hook dependency array tracking layout switches.

Changelog

Refactored the core state mechanics of the custom useCopy hook to handle edge cases and quick-navigation updates seamlessly:

  • Introduced a mutable useRef pointer container (timeoutRef) to tracking scheduled setTimeout identifiers across rendering cycles.
  • Enforced an upfront clearTimeout pass before initializing a new timer instance, resolving visual race conditions from stacked execution intervals.
  • Appended a useEffect synchronization block that automatically unsets the copied visual state whenever the target text prop changes or when the context unmounts.

Screenshots

N/A — Structural hook logic adjustment.

Copilot AI review requested due to automatic review settings June 25, 2026 11:53
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3e9ee9b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @HarshalPatel1972, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Jun 25, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a8dba3fc-bf2d-44fb-8102-5c1a5cc65521

📥 Commits

Reviewing files that changed from the base of the PR and between 82bdd1f and 3e9ee9b.

📒 Files selected for processing (1)
  • apps/webapp/app/hooks/useCopy.ts

Walkthrough

The useCopy hook now keeps the active timeout in a ref, clears any existing timeout before starting a new copied-reset timer, and resets copied when value changes. It also clears the timeout during effect cleanup.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants