docs(eslint-plugin-react-hooks): warn about regex matching in additionalHooks#36096
Open
MorikawaSouma wants to merge 2 commits intofacebook:mainfrom
Open
docs(eslint-plugin-react-hooks): warn about regex matching in additionalHooks#36096MorikawaSouma wants to merge 2 commits intofacebook:mainfrom
MorikawaSouma wants to merge 2 commits intofacebook:mainfrom
Conversation
The profiling documentation links in DevTools were pointing to the legacy reactjs.org domain via fb.me short URLs. Updated all references to point to the current react.dev documentation. Fixes facebook#31878 Changed: - ProfilingNotSupported.js: fb.me/react-devtools-profiling → react.dev/reference/profiler - NoProfilingData.js: fb.me/react-devtools-profiling → react.dev/reference/profiler - TimelineNotSupported.js: fb.me/react-devtools-profiling → react.dev/reference/profiler The old reactjs.org/link/profiling URL redirects to an outdated site that displays a banner stating it's no longer updated.
…nalHooks The additionalHooks option uses regex matching which can catch more than intended. The example regex '(useMyCustomHook|useMyOtherCustomHook)' would match 'useMyCustomHook2' and 'useMyOtherCustomHookTest' which may not be the desired behavior. Added a warning and example with word boundaries to help users avoid this pitfall. Fixes facebook#29045 This issue was reported when WordPress Gutenberg used the same regex pattern and encountered unintended matches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the documentation for the
additionalHooksoption ineslint-plugin-react-hooksby adding a warning about regex matching behavior and providing a better example.Problem
The
additionalHooksoption uses regex matching to identify custom hooks that should have their dependencies validated. However, the example regex in the documentation can match more than intended:Example from docs:
(useMyCustomHook|useMyOtherCustomHook)Unintended matches:
useMyCustomHook- intended matchuseMyCustomHook2- unintended matchuseMyOtherCustomHookTest- unintended matchThis issue was discovered by WordPress Gutenberg when they used the same pattern and encountered bugs due to unintended matches (see WordPress/gutenberg#61598).
Issue: Fixes #29045
Solution
Added a warning to the documentation explaining this behavior and provided an example using word boundaries (
\b) to ensure exact matches:additionalHooks: "\\b(useMyCustomHook|useMyOtherCustomHook)\\b"This pattern will only match:
useMyCustomHook- exact matchuseMyOtherCustomHook- exact matchuseMyCustomHook2- no match (desired behavior)Testing
Impact
This documentation improvement will help users avoid a common pitfall when configuring
additionalHooks, preventing bugs in their applications.This is a documentation-only change with no functional impact on the plugin's behavior.