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

fix(devtools): stop devtools explorer from un-expanding when data is fetched #3687

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/devtools/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Entry = {
}

type RendererProps = {
HandleEntry: HandleEntryComponent
handleEntry: (entry: Entry) => JSX.Element
label?: string
value: unknown
subEntries: Entry[]
Expand Down Expand Up @@ -101,7 +101,7 @@ export function chunkArray<T>(array: T[], size: number): T[][] {
type Renderer = (props: RendererProps) => JSX.Element

export const DefaultRenderer: Renderer = ({
HandleEntry,
handleEntry,
label,
value,
subEntries = [],
Expand All @@ -126,11 +126,7 @@ export const DefaultRenderer: Renderer = ({
</ExpandButton>
{expanded ? (
subEntryPages.length === 1 ? (
<SubEntries>
{subEntries.map(entry => (
<HandleEntry key={entry.label} entry={entry} />
))}
</SubEntries>
<SubEntries>{subEntries.map(handleEntry)}</SubEntries>
) : (
<SubEntries>
{subEntryPages.map((entries, index) => (
Expand All @@ -149,11 +145,7 @@ export const DefaultRenderer: Renderer = ({
{index * pageSize + pageSize - 1}]
</LabelButton>
{expandedPages.includes(index) ? (
<SubEntries>
{entries.map(entry => (
<HandleEntry key={entry.label} entry={entry} />
))}
</SubEntries>
<SubEntries>{entries.map(handleEntry)}</SubEntries>
) : null}
</Entry>
</div>
Expand All @@ -171,8 +163,6 @@ export const DefaultRenderer: Renderer = ({
)
}

type HandleEntryComponent = (props: { entry: Entry }) => JSX.Element

type ExplorerProps = Partial<RendererProps> & {
renderer?: Renderer
defaultExpanded?: true | Record<string, boolean>
Expand Down Expand Up @@ -246,8 +236,14 @@ export default function Explorer({
const subEntryPages = chunkArray(subEntries, pageSize)

return renderer({
HandleEntry: ({ entry }) => (
<Explorer value={value} renderer={renderer} {...rest} {...entry} />
handleEntry: entry => (
<Explorer
key={entry.label}
value={value}
renderer={renderer}
{...rest}
{...entry}
/>
),
type,
subEntries,
Expand Down
2 changes: 1 addition & 1 deletion src/devtools/tests/Explorer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Explorer', () => {
pageSize={10}
expanded={false}
subEntryPages={[[{ label: 'A lovely label' }]]}
HandleEntry={() => <></>}
handleEntry={() => <></>}
value={undefined}
subEntries={[]}
type="string"
Expand Down