wxt
wxt copied to clipboard
fix: add missing timer clear methods to ContentScriptContext
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.
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Thanks for the PR, but why not just call clearTimeout or the other clear functions directly?
@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:
-
API Consistency: The context already provides methods like setTimeout and setInterval, so developers would naturally expect corresponding clear methods to be available as well.
-
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).
-
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.
@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?
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!
I've updated the docs in 030f23d2e9044203ea824e70995535bb60d64978