fix(sidebar): stop counts flickering to 0 and layout collapsing during nav transitions#576
Open
eliran-ops wants to merge 1 commit intomainfrom
Open
Conversation
…g nav transitions
SKY-824 covers two related Resources sidebar regressions:
39. Sidebar resource counts go to "0" for every kind during initial
load instead of preserving last-known values or hiding counts.
Looks like ~2 seconds of "data loss".
65. The hierarchical sidebar (categories like Workloads / Networking)
briefly collapses to the flat fallback (Pods / Deployments /
etc. with all counts 0) during nav transitions, causing UI
flicker.
Root cause:
- The count map coerced *every* missing key to 0 (`resourceCounts[key]
?? 0`), so during the window between "nothing fetched yet" and
"counts payload arrived" every kind rendered a confident "0" badge.
- During route transitions the parent briefly re-renders with
`apiResources={undefined}` for one frame; the sidebar then drops to
the flat `CORE_RESOURCE_TYPES` fallback for that frame, then snaps
back to hierarchical — perceived as a layout flicker.
Fix:
1. New shared hook `useLastDefined<T>(value)` in
`packages/k8s-ui/src/hooks/`. Latches the last non-undefined value
without re-rendering on its own; never replaces a defined value
with stale data. 5 unit tests pin the contract.
2. `ResourcesSidebar` wraps both `apiResources` and `resourceCounts`
in `useLastDefined`, so a one-frame undefined drop doesn't
collapse the layout / blank the badges.
3. Distinguish "loading" from "confirmed zero" in counts:
- Internal `counts: Record<string, number | null>`. `null` means
the count payload hasn't arrived for this key yet; `0` means the
API confirmed zero.
- The badge UI renders an en-dash (`–`) for `null`, with a
`text-theme-text-disabled` class so loading badges are visually
subordinate to live ones.
- Category "show this kind" filter treats null as "show, might
have data" rather than "0, hide".
- Category totals coerce nulls to 0 for the collapsed-summary
badge so we still show *some* number; this is honest because the
total is over a known finite set of kinds.
The `Checks` page mentioned in bug 40 lives in radar-hub-web, not
radar OSS, so it is out of scope for this PR.
Linear: SKY-824
Made-with: Cursor
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.
Summary
SKY-824 — two related Resources sidebar regressions:
Root cause
Fix
Out of scope
The `Checks` page mentioned in bug 40 lives in `radar-hub-web`, not radar OSS.
Test plan
Made with Cursor
Note
Low Risk
UI-only behavior change plus a small shared hook; main risk is subtle regressions in sidebar visibility/count rendering during loading states.
Overview
Prevents
ResourcesSidebarfrom flickering during navigation/loading by latching the last non-undefinedapiResourcesandresourceCountsvalues via a newuseLastDefinedhook.Updates count handling to distinguish loading vs zero (
number | null), rendering a placeholder dash and keeping kinds visible while counts are unknown, instead of briefly showing0everywhere. Adds unit tests foruseLastDefinedand exports it from the hooks index.Reviewed by Cursor Bugbot for commit c0ac5cb. Bugbot is set up for automated code reviews on this repo. Configure here.