Skip to content

fix: nullable topicsData to avoid Data-tab empty-state flash, defensive fault timestamps#64

Merged
bburda merged 2 commits intomainfrom
fix/data-tab-race-and-timestamps
Apr 14, 2026
Merged

fix: nullable topicsData to avoid Data-tab empty-state flash, defensive fault timestamps#64
bburda merged 2 commits intomainfrom
fix/data-tab-race-and-timestamps

Conversation

@bburda
Copy link
Copy Markdown
Contributor

@bburda bburda commented Apr 13, 2026

Pull Request

Summary

Two small independent fixes for entity browsing and fault rendering:

  1. The Data tab no longer flashes an empty state on entity switch. topicsData in EntityDetailPanel is now ComponentTopic[] | null so the Data tab can distinguish three states explicitly:

    • null -> parent fetch in flight, render a skeleton
    • [] -> loaded with no items, fall through to topicsInfo / empty state
    • [...] -> render the list

    This replaces the earlier self-fetch workaround with a single-owner flow (the parent effect is the only fetcher, resets to null at the start of each entity switch and on error) per review feedback. No duplicate HTTP request, no stale localData carry-over.

  2. transformFault tolerates unexpected first_occurred values (zero, negative, ISO 8601 strings, missing/invalid) and falls back to the current time, preventing Invalid Date in the fault list. RawFaultItem.first_occurred is widened to number | string | null | undefined so the type reflects what the transform actually accepts.


Issue


Type

  • Bug fix
  • New feature
  • Breaking change
  • Documentation only

Testing

  • npm run lint clean
  • npm run typecheck clean
  • npm test - 355 tests pass (5 new tests for defensive timestamp parsing)
  • npm run build succeeds
  • Manual: rapid entity switching no longer flashes "No data available" - the Data tab renders a skeleton until the parent fetch resolves, then shows either the items or the fallback

Checklist

  • Breaking changes are clearly described (none)
  • Linting passes (npm run lint)
  • Build succeeds (npm run build)
  • Docs were updated if behavior or public API changed (n/a - bug fixes only)

Copilot AI review requested due to automatic review settings April 13, 2026 18:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Bug-fix PR for the React SPA’s entity browsing and fault rendering: it aims to prevent empty Data tabs during rapid entity switching, and to harden fault timestamp parsing against unexpected gateway payloads.

Changes:

  • Add defensive parsing for RawFaultItem.first_occurred in transformFault, falling back to “now” on invalid/missing values.
  • Add new unit tests covering non-numeric / missing first_occurred.
  • Add a “self-fetch” fallback in EntityDetailPanel’s Data tab when parent-provided topicsData is empty.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/lib/transforms.ts Adds defensive first_occurred parsing to avoid Invalid Date / exceptions.
src/lib/transforms.test.ts Adds tests for timestamp fallback and ISO-string parsing cases.
src/components/EntityDetailPanel.tsx Adds Data tab self-fetch fallback to mitigate empty state during entity switches.

Comment thread src/lib/transforms.ts
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
@bburda bburda self-assigned this Apr 13, 2026
@bburda bburda requested a review from mfaferek93 April 13, 2026 20:43
Comment thread src/lib/transforms.ts
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
Comment thread src/components/EntityDetailPanel.tsx Outdated
…flash

Before: the Data tab panel read `topicsData` as `ComponentTopic[]`
seeded with `[]`. When the user switched entities the parent cleared
the array and then started a fetch; the child could render a full
"no data" panel for the new entity before the fetch resolved,
regardless of what the new entity actually had.

Now: `topicsData` is `ComponentTopic[] | null`. The parent resets it
to `null` at the start of every fetch (including the unsupported-type
branches and on error), and sets it to an array once the response is
in. The Data tab renders a skeleton for `null`, the normal list for a
non-empty array, and the empty/fallback state for `[]`.

This removes the need for a second in-flight request from the child
component and gives the fetch effect a single source of truth.
@bburda bburda force-pushed the fix/data-tab-race-and-timestamps branch from a02224b to d66406d Compare April 14, 2026 15:13
@bburda bburda changed the title fix: Data tab race on entity switch and defensive fault timestamp parsing fix: nullable topicsData to avoid Data-tab empty-state flash, defensive fault timestamps Apr 14, 2026
Accept unix-seconds numbers, ISO 8601 strings, and fall back to the
current time for zero, negative, missing, or otherwise invalid values
instead of letting `new Date()` produce "Invalid Date" in the UI.
Widen `RawFaultItem.first_occurred` to `number | string | null |
undefined` so the type reflects the shapes the transform actually
handles and the fallback branches are not unreachable at the type
level.
@bburda bburda force-pushed the fix/data-tab-race-and-timestamps branch from d66406d to af06e6b Compare April 14, 2026 15:36
@bburda
Copy link
Copy Markdown
Contributor Author

bburda commented Apr 14, 2026

Follow-up on @mfaferek93's review comments left on #66 that apply to the timestamp logic living here:

  • Added console.warn('[transformFault] invalid first_occurred, falling back to now:', ...) in the fallback path so operators get a dev-tools breadcrumb when the gateway ships garbage.
  • Rewrote the timestamp defensive-parsing tests: replaced the tautological not.toThrow checks with a recency assertion (ts within 5s of Date.now()) and verified the console.warn fires exactly once on each invalid input.

Pushed as af06e6b. Tests + lint + typecheck clean.

@mfaferek93 mfaferek93 self-requested a review April 14, 2026 15:47
@bburda bburda merged commit e9a802b into main Apr 14, 2026
3 checks passed
@bburda bburda deleted the fix/data-tab-race-and-timestamps branch April 14, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Empty Data tab on entity switch and crash on non-numeric fault timestamps

3 participants