Add static injection for feature flags#11269
Merged
gaearon merged 2 commits intofacebook:masterfrom Oct 18, 2017
Merged
Conversation
bvaughn
approved these changes
Oct 18, 2017
Contributor
bvaughn
left a comment
There was a problem hiding this comment.
Remove the configuration bit and locate per-package FeatureFlags override automatically.
Using convention to auto-locate src/renderers/*/FeatureFlags.js (if one exists) sounds nice as a potential follow-up.
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.
Related to discussion in #11260.
This does two things:
Removes
ReactDOMFeatureFlagsas a separate entity, instead opting for unified feature flag list across the whole codebase inReactFeatureFlags.Adds a mechanism to specify build-time overrides for the whole
ReactFeatureFlagsfile for a particular bundle.For example, let’s say we have a flag called
includePersistenceImplementation, andreact-native-cswants to flip it totrue. To introduce it, we would need to:ReactFeatureFlags.js:export type FeatureFlags = {| enableAsyncSubtreeAPI: boolean, enableAsyncSchedulingByDefaultInReactDOM: boolean, + includePersistenceImplementation: boolean |}; var ReactFeatureFlags: FeatureFlags = { enableAsyncSubtreeAPI: true, enableAsyncSchedulingByDefaultInReactDOM: false, + includePersistenceImplementation: false, };ReactNativeCSFeatureFlags.js:Note how it has to include all flags since we’re fully forking the file. It might seem a bit annoying but it’s simpler than figuring out how to merge them both at compile, Flow, and test time. Exact Flow types here guard us against mistakes.
name: 'react-native-cs-renderer', + featureFlags: 'src/renderers/native-cs/ReactNativeCSFeatureFlags', paths: [ 'src/renderers/native-cs/**/*.js', 'src/renderers/shared/**/*.js',We can remove this step and make it conventional after #11252.
This should be enough to enable DCE for cases like #11260 because GCC (which we use for
react-dom) is smart enough to read static boolean flags.Potential pitfalls of this approach:
ReactFeatureFlagsneeds to be mocked in tests.Potential future work:
FeatureFlagsoverride automatically.ReactBuildFlagsandReactRuntimeFlagsfor extra clarity?