-
Notifications
You must be signed in to change notification settings - Fork 31.8k
feat: animated dev build/render indicator #74833
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
...rimental/internal/components/Errors/dev-tools-indicator/internal/dev-render-indicator.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Singleton store to track whether the app is currently being rendered | ||
| * Used by the dev tools indicator to show render status | ||
| */ | ||
|
|
||
| import { useSyncExternalStore } from 'react' | ||
|
|
||
| let isVisible = false | ||
| let listeners: Array<() => void> = [] | ||
|
|
||
| const subscribe = (listener: () => void) => { | ||
| listeners.push(listener) | ||
| return () => { | ||
| listeners = listeners.filter((l) => l !== listener) | ||
| } | ||
| } | ||
|
|
||
| const getSnapshot = () => isVisible | ||
|
|
||
| const show = () => { | ||
| isVisible = true | ||
| listeners.forEach((listener) => listener()) | ||
| } | ||
|
|
||
| const hide = () => { | ||
| isVisible = false | ||
| listeners.forEach((listener) => listener()) | ||
| } | ||
|
|
||
| export function useIsDevRendering() { | ||
| return useSyncExternalStore(subscribe, getSnapshot) | ||
| } | ||
|
|
||
| export const devRenderIndicator = { | ||
| show, | ||
| hide, | ||
| } |
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
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
16 changes: 16 additions & 0 deletions
16
...components/Errors/dev-tools-indicator/internal/use-sync-dev-render-indicator-internal.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { useEffect, useTransition } from 'react' | ||
| import { devRenderIndicator } from './dev-render-indicator' | ||
|
|
||
| export const useSyncDevRenderIndicatorInternal = () => { | ||
| const [isPending, startTransition] = useTransition() | ||
|
|
||
| useEffect(() => { | ||
| if (isPending) { | ||
| devRenderIndicator.show() | ||
| } else { | ||
| devRenderIndicator.hide() | ||
| } | ||
| }, [isPending]) | ||
|
|
||
| return startTransition | ||
| } |
20 changes: 20 additions & 0 deletions
20
...rimental/internal/components/Errors/dev-tools-indicator/use-sync-dev-render-indicator.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const NOOP = (fn: () => void) => fn() | ||
|
|
||
| /** | ||
| * Returns a transition function that can be used to wrap router actions. | ||
| * This allows us to tap into the transition state of the router as an | ||
| * approximation of React render time. | ||
| */ | ||
| export const useSyncDevRenderIndicator = () => { | ||
| let syncDevRenderIndicator = NOOP | ||
|
|
||
| if (process.env.NODE_ENV === 'development') { | ||
| const { useSyncDevRenderIndicatorInternal } = | ||
| require('./internal/use-sync-dev-render-indicator-internal') as typeof import('./internal/use-sync-dev-render-indicator-internal') | ||
|
|
||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| syncDevRenderIndicator = useSyncDevRenderIndicatorInternal() | ||
| } | ||
|
|
||
| return syncDevRenderIndicator | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as the logo is concerned it's only ever rendering or building, so I'm wondering if this should be combined into a single enum state? e.g.
IDLE|BUILDING|RENDERINGUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking it through, passing two separate props makes sense because:
Four Possible States: Technically, there are four states (building on/off × rendering on/off). Since dev building and rendering are independent, the Logo component needs to decide how to handle conflicting states (e.g., both building and rendering happening simultaneously). I want that logic to be delegated to Logo instead of preprocessing it beforehand.
Component Behavior: The Logo is already a “smart” component—it includes logic like a 200ms debounce. This makes it more than just a dummy presentational component. Hence, adding a bit more logic to handle multiple states is more consistent with its current responsibilities. (The reason we pass rendering and building props rather than having Logo manage these internally via hooks is to allow flexibility for overrides, such as in Storybook.)