Skip to content

fix: guard against missing context in useFeatureFlag#8176

Merged
francinelucca merged 3 commits into
mainfrom
chore/ff-guard-against-missing-context
Jul 16, 2026
Merged

fix: guard against missing context in useFeatureFlag#8176
francinelucca merged 3 commits into
mainfrom
chore/ff-guard-against-missing-context

Conversation

@francinelucca

Copy link
Copy Markdown
Member

Relates to #8114

This pull request makes a small improvement to the useFeatureFlag hook to make it more robust against missing context. Now, if the FeatureFlagContext is not available, the hook will safely return false instead of throwing an error.

Changelog

Changed

  • Guard against missing context in useFeatureFlag

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Copilot AI review requested due to automatic review settings July 16, 2026 20:20
@francinelucca
francinelucca requested a review from a team as a code owner July 16, 2026 20:20
@francinelucca
francinelucca requested a review from jonrohan July 16, 2026 20:20
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ce8e0e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@francinelucca
francinelucca requested a review from liuliu-dev July 16, 2026 20:20
@github-actions github-actions Bot added the staff Author is a staff member label Jul 16, 2026
@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. If this doesn't work, you can also use the original workflow here. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useFeatureFlag resilient to a missing context by returning false instead 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

Comment thread packages/react/src/FeatureFlags/useFeatureFlag.ts
Comment thread packages/react/src/FeatureFlags/useFeatureFlag.ts
@github-actions
github-actions Bot requested a deployment to storybook-preview-8176 July 16, 2026 20:26 Abandoned
@primer

primer Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

🤖 Lint issues have been automatically fixed and committed to this PR.

@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

@francinelucca
francinelucca added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit f061bc4 Jul 16, 2026
54 checks passed
@francinelucca
francinelucca deleted the chore/ff-guard-against-missing-context branch July 16, 2026 21:23
@primer primer Bot mentioned this pull request Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants