[DevTools] Apply component filters on initial load#392
Conversation
4cba399 to
f34c5b6
Compare
Greptile SummaryThis PR refactors component filter initialization to use an explicit parameter-based approach instead of relying on a global Key improvements:
Notable implementation details:
Confidence Score: 4/5
Important Files Changed
|
Using the localStorage from the frontend has two downsides: - it comes in while we're profiling when we don't support updating filters - it comes in after the initial mount i.e. we always reconcile the full tree twice on initial load Storing it in the backend means data might desync but that complexity is worth avoiding the two issues above. If we get synchronization issues in practice we can revisit.
3031aae to
43a0ec0
Compare
| if (Array.isArray(componentFiltersOrComponentFiltersPromise)) { | ||
| applyComponentFilters(componentFiltersOrComponentFiltersPromise, null); | ||
| } else { | ||
| // Unfortunately this feature is not expected to work for React Native for now. | ||
| // It would be annoying for us to spam YellowBox warnings with unactionable stuff, | ||
| // so for now just skip this message... | ||
| //console.warn('⚛ DevTools: Could not locate saved component filters'); | ||
|
|
||
| // Fallback to assuming the default filters in this case. | ||
| applyComponentFilters(getDefaultComponentFilters(), null); | ||
| componentFiltersOrComponentFiltersPromise.then(componentFilters => { | ||
| applyComponentFilters(componentFilters, null); | ||
| }); | ||
| } |
There was a problem hiding this comment.
style: The promise for component filters has no error handling. If the promise rejects, filters won't be applied and no warning will be logged. This differs from the settings promise handling in hook.js which includes a .catch() with a console error. Consider adding error handling to log a warning if component filters fail to initialize.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-devtools-shared/src/backend/fiber/renderer.js
Line: 1520:1526
Comment:
**style:** The promise for component filters has no error handling. If the promise rejects, filters won't be applied and no warning will be logged. This differs from the settings promise handling in hook.js which includes a `.catch()` with a console error. Consider adding error handling to log a warning if component filters fail to initialize.
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#35587
Original author: eps1lon
The extension wasn't using the persistested filters until you made changes in the frontend. Now we're using the same approach as the hook settings which means the timings works out to be before React renders. That way we don't have to immediately throw out the devtools backend tree like we usually do when updating component filters.
The alternative would be to use the
savedPreferencesmessages like react-devtools-inline does. react-devtools-inline approach is less complex but would come with two downsides:Storing it in the backend means data might desync but that complexity is worth avoiding the two issues above.
If we get synchronization issues in practice we can revisit.
This removes reliance on
__REACT_DEVTOOLS_COMPONENT_FILTERS__in favor of passing a sync value or Promise toinitializeinstead.Test plan
CleanShot.2026-01-21.at.19.40.04.mp4