Skip to content

Fix the "Unsupported node type: PrivateIdentifier" in react-hooks/exhaustive-deps ESLint rule #33455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kossnocorp
Copy link

@kossnocorp kossnocorp commented Jun 6, 2025

Summary

The PR fixes "Unsupported node type: PrivateIdentifier" error in the react-hooks/exhaustive-deps ESLint rule.

I.e. ESLint throws the errors in the following code:

export class Form<Payload> {
  static use<Payload>(
    value: Payload,
    options?: Form.Options<Payload>,
  ): Form<Payload> {
    const id = useId();
    const form = useMemo(() => new Form(id, value, options), [id]);
    const rerender = useRerender();

    useEffect(
      () =>
        form.#field.watch((_, event) => {
          // Only react to form-specific changes, as everything else is
          // handled by the field's useBind hook below.
          if (
            !maskedChanges(
              event.changes,
              formChange.formSubmitting |
                formChange.formSubmitted |
                formChange.formValid |
                formChange.formInvalid,
            )
          )
            return;

          rerender();
        }),
      [form, rerender],
    );

    form.#field.useBind();

    return form;
  }

  // ...
}
Error: Unsupported node type: PrivateIdentifier
Occurred while linting /wrkspc/enso/src/form/index.tsx:20
Rule: "react-hooks/exhaustive-deps"
    at analyzePropertyChain (/wrkspc/enso/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:2532:15)
    at analyzePropertyChain (/wrkspc/enso/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:2506:24)
    at gatherDependenciesRecursively (/wrkspc/enso/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1272:42)
    at visitFunctionWithDependencies (/wrkspc/enso/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1250:13)
    at visitCallExpression (/wrkspc/enso/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:2045:21)
    at ruleErrorHandler (/wrkspc/enso/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1307:33)
    at /wrkspc/enso/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:46
    at Array.forEach (<anonymous>)
    at Object.emit (/wrkspc/enso/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:26)
    at #applySelector (/wrkspc/enso/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/source-code-traverser.js:148:17)

Luckily, it is an easy fix, albeit required some tinkering in tests as babel-eslint doesn't support private methods at all.

How did you test this change?

I tested it on my codebase that actively uses private class properties, and also committed a failing test separately for easier verification.

The exhaustive-deps rule currently doesn't fully support private identifiers, the commit adds a failing test.
@kossnocorp kossnocorp changed the title Eslint private ident Fix the "Unsupported node type: PrivateIdentifier" in react-hooks/exhaustive-deps ESLint rule Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants