Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change useExperimentalFeatures to use the new useSettings API #48125

Merged
merged 9 commits into from
Feb 28, 2023

Conversation

philipp-spiess
Copy link
Contributor

@philipp-spiess philipp-spiess commented Feb 23, 2023

This PR changes the useExperimentalFeatures hook to use the new useSettings API as discussed in #47979.

Test plan

  • Played around with the app locally including changing some feature flag settings
  • CI

App preview:

Check out the client app preview documentation to learn more.

This PR changes the `useExperimentalFeatures` hook to use the new
`useSettings` API as discussed in #47979.
@philipp-spiess philipp-spiess self-assigned this Feb 23, 2023
@cla-bot cla-bot bot added the cla-signed label Feb 23, 2023
@github-actions github-actions bot added the team/code-exploration Issues owned by the Code Exploration team label Feb 23, 2023
@sg-e2e-regression-test-bob
Copy link

sg-e2e-regression-test-bob commented Feb 23, 2023

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (+0.07 kb) -0.02% (-3.32 kb) -0.03% (-3.39 kb) -0.27% (-2) 🔽

Look at the Statoscope report for a full comparison between the commits a594675 and 27d44ce or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

</span>
</div>
</div>
</button>
Copy link
Contributor Author

@philipp-spiess philipp-spiess Feb 23, 2023

Choose a reason for hiding this comment

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

This snapshot change happens because we enable codeMonitoringWebHooks is now enabled by default but the test was not covering the default settings properly. It only adds a CTA and is unrelated to the assertion though :)

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Feb 23, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff 27d44ce...a594675.

Notify File(s)
@fkling client/web/src/search/SearchConsolePage.tsx
client/web/src/search/home/SearchPageInput.tsx
client/web/src/search/input/SearchNavbarItem.tsx
client/web/src/search/results/SearchResultsCacheProvider.tsx
client/web/src/search/results/StreamingSearchResults.tsx
client/web/src/search/results/sidebar/SearchFiltersSidebar.tsx
client/web/src/search/useExperimentalSearchInput.ts
@limitedmage client/web/src/enterprise/code-monitoring/CodeMonitoringPage.tsx
client/web/src/enterprise/code-monitoring/components/FormActionArea.tsx
client/web/src/enterprise/code-monitoring/components/FormTriggerArea.tsx
client/web/src/enterprise/code-monitoring/components/snapshots/FormActionArea.test.tsx.snap
client/web/src/search/SearchConsolePage.tsx
client/web/src/search/home/SearchPageInput.tsx
client/web/src/search/input/SearchNavbarItem.tsx
client/web/src/search/results/SearchResultsCacheProvider.tsx
client/web/src/search/results/StreamingSearchResults.tsx
client/web/src/search/results/sidebar/SearchFiltersSidebar.tsx
client/web/src/search/useExperimentalSearchInput.ts

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Awesome follow-up, @philipp-spiess!

Comment on lines 272 to 273
// eslint-disable-next-line no-console
console.error(
Copy link
Member

Choose a reason for hiding this comment

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

The console.x methods are banned so we don't forget them in our PRs and to allow us to control the console output in place, where we potentially can send these logs/errors to other services like Sentry, Honeycomb, etc.

import { logger } from '@sourcegraph/common'
logger.error(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Is there a way to extend the error message here to explain this?

Screenshot 2023-02-24 at 10 49 44

We have a lot of annoying eslint rules so I just try to make them go away quickly. In this case, I wasn't aware that this is for a good reason and the message didn't explain it either.

Copy link
Member

Choose a reason for hiding this comment

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

We have a lot of annoying eslint rules so I just try to make them go away quickly.

True, we also have a bunch of duplicate rules because of multiple plugins we use. Let's raise this in #chat-frontend next time it happens so we can remove redundant rules and better document others.

Is there a way to extend the error message here to explain this?

There's no super straightforward way to do it AFAIK. We cannot use no-restricted-syntax because it already has a warning level. We cannot add a custom message to the no-console rule, according to the docs. We can probably create a custom rule and add our message there. Let me know if you see a better way. Here's the related section in our documentation that can be used in the custom error message.

Comment on lines +49 to +52
const { enableGoImportsSearchQueryTransform, applySuggestionsOnEnter } = useExperimentalFeatures(features => ({
enableGoImportsSearchQueryTransform: features.enableGoImportsSearchQueryTransform,
applySuggestionsOnEnter: features.applySearchQuerySuggestionOnEnter ?? true,
}))
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we don't need a selector function in most cases. Would it be good enough to return the experimental features object by default to avoid redundant field mapping?

Suggested change
const { enableGoImportsSearchQueryTransform, applySuggestionsOnEnter } = useExperimentalFeatures(features => ({
enableGoImportsSearchQueryTransform: features.enableGoImportsSearchQueryTransform,
applySuggestionsOnEnter: features.applySearchQuerySuggestionOnEnter ?? true,
}))
const { enableGoImportsSearchQueryTransform, applySuggestionsOnEnter = true } = useExperimentalFeatures()
  1. As we discussed, there should be no performance issues caused by this update because the experimental features object is not mutable. We load it once and use it during the lifetime of the application. Updates are rare, and it's ok to re-rerender UI when they happen.
  2. It's important to discourage the renaming of things. With the selector API, it's easy to save keystrokes and name these settings as something else. Then find-and-replace doesn't work as well as it should, and it makes it harder to follow the logic in components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The object is mutated when the user settings change and in at least one feature that I’m aware of it is also mutated from inside the app code. I don't think the mental model of this being static is safe to apply here, but yeah it's rarely changed which makes it great for context.

My thinking was that we keep the API so we don't have to update all call sites and we can in the future use reactjs/rfcs#119 to make things faster again.

I can look into the change if you feel strongly though!

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, let's keep it and also save time on refactoring 👍

* This is a helper function to hide the fact that experimental feature flags
* are backed by a Zustand store
*/
export function getExperimentalFeatures(): SettingsExperimentalFeatures {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Is it twice a less code for the same functionality now?

@valerybugakov valerybugakov merged commit 9efe84c into main Feb 28, 2023
@valerybugakov valerybugakov deleted the ps/change-useExperimentalFeatures branch February 28, 2023 09:06
@valerybugakov
Copy link
Member

@philipp-spiess, going ahead with merging this because I want to use this neat improvement in my work. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed storm team/code-exploration Issues owned by the Code Exploration team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants