Skip to content

Guard chart components against null streaming data#487

Open
CodexNexor wants to merge 3 commits into
thesysdev:mainfrom
CodexNexor:fix/chart-null-guard
Open

Guard chart components against null streaming data#487
CodexNexor wants to merge 3 commits into
thesysdev:mainfrom
CodexNexor:fix/chart-null-guard

Conversation

@CodexNexor
Copy link
Copy Markdown

Summary

  • add a shared ensureChartData() helper that normalizes null/undefined chart data to []
  • apply the runtime guard across the GenUI-facing chart components that can receive partial streaming props before the full payload arrives
  • keep export/legend/domain calculations aligned with the guarded data so Recharts never receives a null dataset during streaming

Why this fix

The chart schemas in current main already require the expected fields, but that still doesn't fully protect the runtime streaming path when partial data reaches the components before the payload is complete. This PR adds the missing runtime safety layer without changing the public API.

Validation

  • ran git diff --check
  • manually verified the guarded components now derive their Recharts data prop from ensureChartData(...)

Closes #355.

@ankit-thesys ankit-thesys self-assigned this May 11, 2026
Copy link
Copy Markdown
Contributor

@ankit-thesys ankit-thesys left a comment

Choose a reason for hiding this comment

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

Changes look good. Can you fix the build issue? You are good to go with this PR.

@CodexNexor
Copy link
Copy Markdown
Author

Fixed the build issue and pushed an update to this PR.

Root cause was a Prettier failure in two chart files touched by this change.

Latest commit: 67077e3 (Fix formatting in chart null guard changes)

Please recheck when you get a chance.

@ankit-thesys
Copy link
Copy Markdown
Contributor

ankit-thesys commented May 11, 2026

Just read the issue. Have you tried the solution suggested there?
I think this is not required in the component library; instead, it should be handled by the renderer or consumer.

@CodexNexor
Copy link
Copy Markdown
Author

Updated this PR to follow your suggestion.

I moved the runtime guard out of the chart component library and into packages/react-ui/src/genui-lib, so incomplete streamed props now short-circuit in the renderer layer before chart data reaches the components.

What changed in this update:

  • reverted the components/Charts/* null-guard changes from this PR
  • added stricter streamed-prop normalization in genui-lib/helpers.ts
  • reused those helpers in the chart wrappers for array charts, categorical charts, and scatter datasets
  • kept legacy slice fallback behavior intact

Latest commit: 556a592 (Move chart null guards into genui renderer)

Validation on my side:

  • git diff --check
  • targeted Prettier check on the touched files using the repo's Prettier settings/plugin

I couldn't run the full workspace typecheck/build here because this environment doesn't have the repo toolchain installed, but the PR is now aligned with the renderer/consumer approach you mentioned. Please recheck when you get a chance.

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.

Charts component crashes with TypeError during streaming: null data passed to Recharts

2 participants