Skip to content

core: always include headers even for empty tables #16534

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

Merged
merged 4 commits into from
Jun 12, 2025
Merged

Conversation

connorjclark
Copy link
Collaborator

Seems like a good idea to me. Sample LHR went from 528kb -> 540kb.

Idea came from playing with Gemini:

core/audits/audit.js - makeTableDetails returns an empty array for headings when results are empty, but a processed array of heading objects otherwise. This inconsistency means consumers of the table details
must handle two different "shapes" for the headings property depending on whether the table has items. If a UI renderer always expects headings to be populated with the defined column structure (even for an
empty table), this could lead to rendering issues or errors.

More details:

makeTableDetails in core/audits/audit.js has inconsistent headings output. The makeTableDetails function takes headings (an array of heading definition objects) as an argument. If the results array
(table rows) is empty, it returns: { type: 'table', headings: [], items: [], summary } Here, headings is an empty array. If results is not empty, it eventually returns (structure inferred from typical usage and the
need to process keys): { type: 'table', headings: processedHeadingsArray, items: processedItemsArray, ... } Where processedHeadingsArray would be derived from the input headings. This means the headings property in
the returned object has a different nature based on whether there are items. Consumers (like UI rendering components) might expect details.headings to always reflect the defined column structure, even if
details.items is empty. Returning [] for headings when the table is empty means the information about what columns would have been present is lost. This can lead to UI tables rendering without headers for empty
data sets, or requiring special handling by the consumer.

@connorjclark connorjclark requested a review from a team as a code owner June 11, 2025 21:01
@connorjclark connorjclark requested review from paulirish and removed request for a team June 11, 2025 21:01
Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

yeah i dig it. nice to provide the 'types' regardless.

@connorjclark connorjclark merged commit d183f83 into main Jun 12, 2025
28 checks passed
@connorjclark connorjclark deleted the always-headers branch June 12, 2025 00:10
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.

2 participants