fix: guard against missing context in useFeatureFlag#8176
Conversation
🦋 Changeset detectedLatest commit: ce8e0e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Pull request overview
This PR hardens the useFeatureFlag hook so it no longer crashes rendering when FeatureFlagContext is unexpectedly missing (e.g. due to duplicate/partial @primer/react bundles), aligning with the issue report in #8114.
Changes:
- Make
useFeatureFlagresilient to a missing context by returningfalseinstead of throwing.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/FeatureFlags/useFeatureFlag.ts | Adds an optional chaining + nullish-coalescing guard to avoid runtime throws when context is missing. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Low
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
|
Integration test results from github/github-ui PR:
All checks passed! |
Relates to #8114
This pull request makes a small improvement to the
useFeatureFlaghook to make it more robust against missing context. Now, if theFeatureFlagContextis not available, the hook will safely returnfalseinstead of throwing an error.Changelog
Changed
useFeatureFlagRollout strategy
Testing & Reviewing