wxt icon indicating copy to clipboard operation
wxt copied to clipboard

fix: add missing timer clear methods to ContentScriptContext

Open kikutadev opened this issue 8 months ago • 5 comments

Overview

Added missing timer clear methods (clearTimeout, clearInterval, cancelAnimationFrame, cancelIdleCallback) to the ContentScriptContext class. The current class provides corresponding timer creation methods (setTimeout, setInterval, etc.) but lacks methods to clear them, causing TypeScript compilation errors.

Manual Testing

Test with code using ContentScriptContext like:

const timerId = ctx.setTimeout(() => {
  console.log('This should not run');
}, 1000);

ctx.clearTimeout(timerId); // This should work properly

Related Issue

No related issue.

kikutadev avatar Mar 08 '25 18:03 kikutadev

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
Latest commit 39779fd150bbadc29bf48768d63dd819c0699c23
Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/67cc8a4e44f15c00084cd3b4
Deploy Preview https://deploy-preview-1507--creative-fairy-df92c4.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 08 '25 18:03 netlify[bot]

Thanks for the PR, but why not just call clearTimeout or the other clear functions directly?

aklinker1 avatar Mar 08 '25 22:03 aklinker1

@aklinker1 Thank you for reviewing my PR.

I understand that directly using global functions like clearTimeout would technically work, but I proposed these additions for the following reasons:

  1. API Consistency: The context already provides methods like setTimeout and setInterval, so developers would naturally expect corresponding clear methods to be available as well.

  2. Documentation Clarity: While the documentation shows examples of using ctx.setTimeout(), it doesn't mention how to clear these timers, which can be confusing for developers. (I personally was confused when I encountered type errors using ctx.clearTimeout(), and ended up creating a d.ts file to wrap wxt/client).

  3. Type Safety: I was concerned that getting a timer ID from ctx.setTimeout() and then trying to use the global clearTimeout might cause type confusion or inconsistencies.

While I acknowledge that not adding these clear methods wouldn't necessarily cause problems, I believe making these additions would create a more intuitive and consistent developer experience. That said, I'm open to your thoughts on the best approach.

kikutadev avatar Mar 09 '25 16:03 kikutadev

@aklinker1 Thank you for your feedback. I understand your reasoning about the context object's purpose and agree that documentation improvements would be better than adding these methods.

I'm happy to close this PR since the type safety concerns will be addressed in #1531 .

Sorry for not fully understanding the project's contribution guidelines. This was my first contribution attempt. Would you prefer I close this PR?

kikutadev avatar Apr 02 '25 05:04 kikutadev

If you want to be the one to update the docs, feel free to keep it open and update it or close and open another PR. If not, close it and I can update them!

aklinker1 avatar Apr 03 '25 15:04 aklinker1

I've updated the docs in 030f23d2e9044203ea824e70995535bb60d64978

aklinker1 avatar Jun 05 '25 05:06 aklinker1