Draft
Conversation
More aggressive memoization of theme provider and related components to avoid over re-rendering of components that depend on things like the resolvedColorMode. Additionally add useMemo: * error boundary - prevent high level app-wrap re-renders * EventLoopProvider - prevents event loop re-rendering when the location/params/navigate hooks change
Contributor
Greptile SummaryThis PR adds aggressive memoization across several React context providers and high-level components to prevent spurious re-renders that cascade through the component tree.
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[App Layout] --> B[ThemeProvider]
B --> C[StateProvider]
C --> D[EventLoopProvider]
D --> E[AppWrap / ErrorBoundary]
E --> F[Page Components]
B -- "useEffect fix: media query listener<br/>runs only on mount now" --> B
G[RadixThemesColorModeProvider] -- "useCallback: toggleColorMode, setColorMode<br/>useMemo: Provider createElement" --> G
D -- "useMemo: Provider createElement<br/>deps: addEvents, connectErrors, children" --> D
E -- "memo(): error boundary isolated<br/>from app-wrap re-renders" --> E
style B fill:#d4edda,stroke:#28a745
style D fill:#d4edda,stroke:#28a745
style E fill:#d4edda,stroke:#28a745
style G fill:#d4edda,stroke:#28a745
Last reviewed commit: 865d2d7 |
| import reflexEnvironment from "$/reflex.json"; | ||
| import Cookies from "universal-cookie"; | ||
| import { useCallback, useEffect, useRef, useState } from "react"; | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from "react"; |
Contributor
There was a problem hiding this comment.
Unused useMemo import
useMemo was added to this import but is never used anywhere in state.js. The useMemo usage for EventLoopProvider lives in the generated context template (templates.py), not in this file. This will cause lint warnings for unused imports.
Suggested change
| import { useCallback, useEffect, useMemo, useRef, useState } from "react"; | |
| import { useCallback, useEffect, useRef, useState } from "react"; |
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.
More aggressive memoization of theme provider and related components to avoid over re-rendering of components that depend on things like the resolvedColorMode.
Additionally add useMemo: