Skip to content

fix(purity): remove AbortController from impure constructors#1648

Merged
Rel1cx merged 3 commits intoRel1cx:mainfrom
zerone0x:fix/abort-controller-purity
Mar 28, 2026
Merged

fix(purity): remove AbortController from impure constructors#1648
Rel1cx merged 3 commits intoRel1cx:mainfrom
zerone0x:fix/abort-controller-purity

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

Summary

  • Remove AbortController from the IMPURE_CTORS set, since new AbortController() is a pure operation that creates an in-memory object without side effects (no I/O, no DOM mutation, no event listeners).
  • Move AbortController test cases from invalid to valid in the purity rule spec.

Closes #1625

Test plan

  • All 147 existing purity rule tests pass
  • Added valid test case for new AbortController() directly in a component render path
  • Existing valid tests for AbortController inside useEffect still pass

`new AbortController()` is a pure operation that creates an in-memory
object without side effects (no I/O, no DOM mutation, no listeners).
It should not be flagged by the purity rule.

Closes Rel1cx#1625

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

@zerone0x is attempting to deploy a commit to the Rel1cx's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eslint-react Ready Ready Preview, Comment Mar 27, 2026 6:03pm

Request Review

@Rel1cx Rel1cx requested a review from Copilot March 28, 2026 06:21
@Rel1cx Rel1cx merged commit f9fc792 into Rel1cx:main Mar 28, 2026
8 of 9 checks passed
Copy link
Copy Markdown
Contributor

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

Updates the purity ESLint rule’s impure-constructor list and test suite to treat new AbortController() as a pure operation, resolving false-positive reports (Closes #1625).

Changes:

  • Removed AbortController from the IMPURE_CTORS set.
  • Updated purity rule tests by moving new AbortController() from invalid to valid.

Reviewed changes

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

File Description
packages/shared/src/constants.ts Stops classifying AbortController as an impure constructor so it won’t be flagged during render.
packages/plugins/eslint-plugin-react-x/src/rules/purity/purity.spec.ts Adjusts test expectations so new AbortController() is allowed in component render paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 843 to 851
{
code: tsx`
function Component() {
const ws = new (WebSocket as any)("ws://example.com");
return <div>Content</div>;
}
`,
errors: [{ messageId: "default" }],
},
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

PR description says AbortController test cases were moved from invalid to valid, but the type-wrapped constructor case (new (AbortController as any)()) was removed from invalid without being added to valid. Consider adding an explicit valid case for the type-wrapped AbortController constructor (or update the PR description) to avoid losing coverage for this scenario.

Copilot uses AI. Check for mistakes.
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.

[bug] Purity flags instantiating refs with new AbortController()

3 participants