Repository navigation
feat(lint): lint the context hook contract in packages/react - #575
Merged
kianbazza merged 1 commit intoSep 29, 2026
Conversation
kianbazza
added this pull request to stack #572
September 29, 2026 14:48
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Adds `bazza/context-hook-contract`: a `useX` hook that reads a context created with a `null` default checks it and throws, or falls back to a non-null value; a hook that can return the missing context is named `useMaybeX`. The seven hooks that break it today are allowlisted. `packages/react/AGENTS.md` documents the pattern.
kianbazza
force-pushed
the
ui-618-lint-the-context-hook-contract
branch
from
September 29, 2026 15:08
7dffdcf to
53bbb9c
Compare
kianbazza
marked this pull request as ready for review
September 29, 2026 15:41
This branch was successfully deployed
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
bazza/context-hook-contractenforces the naming contract for context hooks inpackages/react/src. A context created with anulldefault is missing when a part renders outside its provider.useXpromises a value or a clear error. A hook that can hand back the missing context is nameduseMaybeX.return, a top-leveliftests that exact variable for the missing value (!ctx,ctx == null, or=== nullfor anulldefault) and always throws. A?? fallbackwhose fallback can't benullalso counts.useContext(Ctx) !== nulloruseContext(Ctx)?.depth.invariant(ctx)or a flag-guarded throw, get a "can't tell" report without the rename advice.useContextinsrctoday reads one of those.useGroupContextuseSelectPositionerContextuseComboboxPositionerContextuseGraftPointuseMenuTreeResolverusePopupSurfaceIduseAsyncMenuCoordinator, which is identical touseMaybeAsyncMenuCoordinatorisCallTo,outermostWrapper,variableOf) move intotooling/lint/rules/ast.mjs, and the earlier rules use them.packages/react/AGENTS.mdgets a "Context hooks" section.Evidence
useFooContext() { return React.useContext(FooContext) }passedbun run check, and the first sign of trouble was anullcrash somewhere downstream.After:
useVideoPlayerContext(component),useContextMenuInternaland the seek slider's inline context.tooling/linttests grow to 64. They cover every accepted proof shape, and every lookalike that can still returnnull: a flag-guarded throw, a dev-only throw,=== undefinedagainst anulldefault, a check on a property, an early return,?? null, and checking a different variable.Merge Danger
Door: two-way
Blast Radius: tooling
New context hooks in
packages/react/srcmust throw or be nameduseMaybe*. Existing hooks are unaffected until someone removes them from the allowlist.Closes UI-618