Skip to content

strimzi: Fix crash when the Kafka cluster list is still loading - #917

Merged
illume merged 1 commit into
headlamp-k8s:mainfrom
cesaroangelo:strimzi-fix-null-list-crash
Jul 21, 2026
Merged

strimzi: Fix crash when the Kafka cluster list is still loading#917
illume merged 1 commit into
headlamp-k8s:mainfrom
cesaroangelo:strimzi-fix-null-list-crash

Conversation

@cesaroangelo

@cesaroangelo cesaroangelo commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Problem

Opening the Kafka Topics or Kafka Users page throws
Cannot read properties of null (reading 'map') and blanks the page.
It is reliably reproducible on a cluster that has no topics or users (the
lists render before the Kafka cluster list has resolved).

KubeObject.useList().items is typed Array<T> | null and is null while
the query is loading, but both list components mapped over it directly to
build the create-dialog namespace/cluster dropdowns.

Fix

  • Normalise the cluster list to an array at the useList call site.
  • Extract the dropdown derivations into null-tolerant helpers
    (clusterNamespaces, clusterNamesInNamespace) with unit tests covering
    the null/loading case, so the crash cannot silently regress.
  • De-duplicate the shared KafkaClusterRef type into utils.

It's a small, self-contained change, and the null handling is covered by
unit tests. tsc, eslint, prettier and the full test suite (71 tests)
pass.

Note

This is a focused, standalone fix for the crash only. #850 also touches this
null crash, but bundles it with a v1-resources rework that has since landed
on main separately, and appears stale.

KafkaClass.useList().items is null while the query is loading (and on
error), but KafkaTopicList and KafkaUserList mapped over it directly to
build the namespace and cluster-name dropdowns. That threw
"Cannot read properties of null (reading 'map')" and blanked the page
whenever the lists were opened before the cluster list resolved, e.g.
on a cluster with no topics or users.

Normalise the cluster list to an array at the useList call site, and
extract the dropdown derivations into null-tolerant helpers
(clusterNamespaces, clusterNamesInNamespace) covered by unit tests. Also
de-duplicate the shared KafkaClusterRef type into utils.

Signed-off-by: Angelo Cesaro <cesaro.angelo@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Strimzi plugin crash on the Kafka Topics and Kafka Users pages that occurred when the Kafka cluster list was still loading (useList().items === null) and the UI attempted to .map() over it.

Changes:

  • Added null-tolerant helpers for deriving namespaces and cluster names from a possibly-null cluster list, with unit tests for the loading/null case.
  • Updated Kafka Topic/User list components to normalize useList().items to an array and reuse the shared helpers.
  • Centralized the shared KafkaClusterRef type into src/utils/clusters.ts and updated component type imports.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
strimzi/src/utils/clusters.ts Adds null-safe cluster list derivation helpers and shared KafkaClusterRef type.
strimzi/src/utils/clusters.test.ts Unit tests covering null/loading and sorting/uniqueness behavior.
strimzi/src/components/TopicFormModal.tsx Replaces local KafkaClusterRef type with shared utils type import.
strimzi/src/components/KafkaUserList.tsx Normalizes useList results, uses shared helpers to avoid null crash.
strimzi/src/components/KafkaUserCreateFormModal.tsx Replaces local KafkaClusterRef type with shared utils type import.
strimzi/src/components/KafkaTopicList.tsx Normalizes useList results, uses shared helpers to avoid null crash.
strimzi/CHANGELOG.md Documents the crash fix under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉 thanks!

@illume
illume merged commit fb4b5ba into headlamp-k8s:main Jul 21, 2026
6 checks passed
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.

3 participants