Skip to content

Clicking Copy repeatedly makes the button label flicker #49

Description

@pushpam2404

Context

js/copy-code.js sets the label to "Copied" and schedules a setTimeout to put it back after 1600ms. Clicking again before that fires schedules a second timer while the first is still pending, so the label reverts early and can flicker between states.

What to change

Files: js/copy-code.js

Requirements:

  • Keep a reference to the pending timer and clear it before starting a new one
  • Rapid clicks should mean the label stays "Copied" for the full period after the last click
  • Per button — one block's timer must not affect another's
  • Do not introduce a global; the existing code is an IIFE per block for a reason

Acceptance criteria

  • Clicking five times quickly leaves "Copied" showing for the full duration after the last click
  • No flicker
  • Two different code blocks behave independently
  • The clipboard still receives the right text

How to verify locally

Open any page with code blocks and click one Copy button five times in a second.

python3 -m http.server 8000

Then open http://localhost:8000.

Difficulty

Intermediate. A small, satisfying bug with a clear reproduction.


New here? Comment /claim on this issue and a bot will assign it to you. Then read CONTRIBUTING.md.

Stuck at any point? Comment here saying what you have tried and where it stopped working — that is not an admission of failure, it is how we find out the instructions were unclear. You can also come to a PR Debug Clinic (Oct 12 or Oct 21).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokendifficulty: intermediateRequires reading existing codedomain: os-devxOpen Source & Developer ExperiencehacktoberfestCounts toward Hacktoberfest 2026

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions