-
Notifications
You must be signed in to change notification settings - Fork 50.4k
[DevTools] Avoid renders of stale Suspense store #34396
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
eps1lon
merged 1 commit into
facebook:main
from
eps1lon:sebbie/09-05-_devtools_avoid_renders_of_stale_suspense_store
Sep 8, 2025
+73
−76
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,10 @@ import type Store from '../../store'; | |
|
|
||
| import * as React from 'react'; | ||
| import {useContext, useLayoutEffect, useMemo, useRef, useState} from 'react'; | ||
| import {BridgeContext, StoreContext} from '../context'; | ||
| import {BridgeContext} from '../context'; | ||
| import {TreeDispatcherContext} from '../Components/TreeContext'; | ||
| import {useHighlightHostInstance} from '../hooks'; | ||
| import {SuspenseTreeStateContext} from './SuspenseTreeContext'; | ||
| import {useSuspenseStore} from './SuspenseTreeContext'; | ||
| import styles from './SuspenseTimeline.css'; | ||
| import typeof { | ||
| SyntheticEvent, | ||
|
|
@@ -63,14 +63,14 @@ function getSuspendableDocumentOrderSuspense( | |
|
|
||
| function SuspenseTimelineInput({rootID}: {rootID: Element['id'] | void}) { | ||
| const bridge = useContext(BridgeContext); | ||
| const store = useContext(StoreContext); | ||
| const store = useSuspenseStore(); | ||
| const dispatch = useContext(TreeDispatcherContext); | ||
| const {highlightHostInstance, clearHighlightHostInstance} = | ||
| useHighlightHostInstance(); | ||
|
|
||
| const timeline = useMemo(() => { | ||
| return getSuspendableDocumentOrderSuspense(store, rootID); | ||
| }, [store, rootID]); | ||
| }, [store, store.revisionSuspense, rootID]); | ||
|
|
||
| const inputRef = useRef<HTMLElement | null>(null); | ||
| const inputBBox = useRef<ClientRect | null>(null); | ||
|
|
@@ -161,6 +161,7 @@ function SuspenseTimelineInput({rootID}: {rootID: Element['id'] | void}) { | |
| function handleFocus() { | ||
| const suspense = timeline[value]; | ||
|
|
||
| dispatch({type: 'SELECT_ELEMENT_BY_ID', payload: suspense.id}); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by. Felt odd to not select the element when you tab/click in but then start selecting when values change. |
||
| highlightHostInstance(suspense.id); | ||
| } | ||
|
|
||
|
|
@@ -213,10 +214,10 @@ function SuspenseTimelineInput({rootID}: {rootID: Element['id'] | void}) { | |
| } | ||
|
|
||
| export default function SuspenseTimeline(): React$Node { | ||
| const store = useContext(StoreContext); | ||
| const {shells} = useContext(SuspenseTreeStateContext); | ||
| const store = useSuspenseStore(); | ||
|
|
||
| const defaultSelectedRootID = shells.find(rootID => { | ||
| const roots = store.roots; | ||
| const defaultSelectedRootID = roots.find(rootID => { | ||
| const suspense = store.getSuspenseByID(rootID); | ||
| return ( | ||
| store.supportsTogglingSuspense(rootID) && | ||
|
|
@@ -239,20 +240,18 @@ export default function SuspenseTimeline(): React$Node { | |
| return ( | ||
| <div className={styles.SuspenseTimelineContainer}> | ||
| <SuspenseTimelineInput key={selectedRootID} rootID={selectedRootID} /> | ||
| {shells.length > 0 && ( | ||
| {roots.length > 0 && ( | ||
| <select | ||
| aria-label="Select Suspense Root" | ||
| className={styles.SuspenseTimelineRootSwitcher} | ||
| onChange={handleChange}> | ||
| {shells.map(rootID => { | ||
| onChange={handleChange} | ||
| value={selectedRootID}> | ||
| {roots.map(rootID => { | ||
| // TODO: Use name | ||
| const name = '#' + rootID; | ||
| // TODO: Highlight host on hover | ||
| return ( | ||
| <option | ||
| key={rootID} | ||
| selected={rootID === selectedRootID} | ||
| value={rootID}> | ||
| <option key={rootID} value={rootID}> | ||
| {name} | ||
| </option> | ||
| ); | ||
|
|
||
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
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.
Naming was confusing. The Shell is a slice from Root to the first boundaries. The Root is a single element.