Skip to content

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

@controversial

Description

@controversial

Describe the bug

Constructing an AbortController triggers the purity rule, even though it is a pure operation

Reproduction

export function useMyHook() {
  // flags for purity:
  const abortControllerRef = useRef(new AbortController());
  // also flags: pattern from https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents
  const abortControllerRef2 = useRef<AbortController>(null);
  if (abortControllerRef2.current === null) {
    abortControllerRef2.current = new AbortController();
  }
  // Does not flag: equivalent useState initializer:
  const abortController = useState(() => new AbortController());
}

Expected behavior

None of the above examples should flag for purity

Platform and versions

plugin 3.0.0 stable; node 24

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: ReleasedThe issue has been releasedType: BugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions