Skip to content

Conversation

@joshblack
Copy link
Member

@joshblack joshblack commented Feb 15, 2024

Add an exploration for introducing feature flags to @primer/react. This PR introduces a new component, FeatureFlags, that is responsible for enabling or disabling flags in a specific tree of components. It also introduces hooks, useFeatureFlag and useFeatureFlags, as ways for maintainers to determine if a feature is flagged in or not.

<FeatureFlags flags={flags}>
  <ExampleReactApp />
</FeatureFlags>
function ExampleComponent(props) {
  const enabled = useFeatureFlag('enable_new_feature');

  return <button onClick={() => { enabled ? newBehavior() : oldBehavior() }}>...</button>;
}

This PR also includes some docs for how to approach this for things like TypeScript, testing, and (in the future) hopefully I way to interact with flags in Storybook.

Changelog

New

  • Add FeatureFlags component
  • Add useFeatureFlag hook
  • Add useFeatureFlags hook

Changed

Removed

Rollout strategy

  • Minor release

Introduce in experimental entrypoint for testing

@changeset-bot
Copy link

changeset-bot bot commented Feb 15, 2024

🦋 Changeset detected

Latest commit: 154d575

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 Minor

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 15, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 88 KB (0%)
packages/react/dist/browser.umd.js 88.25 KB (0%)

@github-actions github-actions bot temporarily deployed to storybook-preview-4276 February 15, 2024 16:01 Inactive
@joshblack
Copy link
Member Author

Note from UI mob pairing: add support for providing a (sync) function to check if something is enabled

@github-actions
Copy link
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 15, 2024
@github-actions github-actions bot temporarily deployed to storybook-preview-4276 April 15, 2024 18:40 Inactive
@github-actions github-actions bot removed the Stale label Apr 15, 2024
@github-actions github-actions bot temporarily deployed to storybook-preview-4276 April 15, 2024 19:10 Inactive
@joshblack joshblack changed the title feat: add feature flags exploration feat: add support for feature flags Apr 15, 2024
@github-actions github-actions bot temporarily deployed to storybook-preview-4276 April 15, 2024 19:16 Inactive
@siddharthkp
Copy link
Member

siddharthkp commented Apr 16, 2024

Great idea! Love to see it.

Short feedback on usage: I think we should make the first iteration a little simpler for ourselves. I'm a little hesitant to support nested scopes right off the bat because usage in gh/gh can quickly get really hard to debug. (I'm thinking inconsistencies between pages, untested combination of feature flags, single instances of a component used with feature flag or the opposite)

Ideally, I'd like to start with a broad boundary (adjacent to ThemeProvider) and once we have some experience with it (and related tooling), make it more advanced.

Note for future: It would be nice if we had a common ThemeProvider across gh/gh and it was called something like PrimerProvider / PrimerContainer / PrimerBoundary (with exceptions for charting etc.)

@joshblack
Copy link
Member Author

@siddharthkp would love to do something like PrimerApp or some kind of "App-level" component like what you described 👍 it would make it simple to add in things as "defaults" to projects that use Primer as a result.

And happy to defer on nesting if that would be helpful 👍 I think the only thing that felt critical is that we want a set of "default" feature flags (in this case the global ones) and that this should be merged in with what is given at the FeatureFlags level. This seemed important because otherwise call sites to FeatureFlags need to manage all flags and their default value, even if it's unrelated to what is being authored.

@joshblack joshblack marked this pull request as ready for review April 18, 2024 15:44
@joshblack joshblack requested a review from a team as a code owner April 18, 2024 15:44
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Looking good!

I know you're going to write tests, approving in advance

@joshblack joshblack enabled auto-merge April 18, 2024 19:53
@joshblack joshblack added this pull request to the merge queue Apr 18, 2024
Merged via the queue into main with commit 13971c9 Apr 18, 2024
@joshblack joshblack deleted the feat/add-feature-flags-component branch April 18, 2024 20:11
@primer primer bot mentioned this pull request Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants