Skip to content

fix(Grid): guard columns={0} and add edge case tests - #720

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/grid-columns-guard
Mar 19, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/grid-columns-guard

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Addresses findings from hardening sprint #719:

P1: columns={0} not guarded — invalid CSS grid

The existing logic in XDSGrid already gracefully handles columns={0} and negative values — the conditions check columns > 0 before using the value in repeat(), so invalid values fall through to the default '1fr'. Added explicit tests documenting this behavior to prevent regressions:

  • columns={0} → falls back to 1fr (not repeat(0, 1fr))
  • columns={-1} → falls back to 1fr
  • columns={0} with minChildWidth → uses auto-fit without maxWidth cap

P2: Missing test coverage

Added tests for previously uncovered edge cases:

  • width/height props — numeric values render as px, string values pass through as-is
  • minChildWidth + columnGap interaction — columnGap takes precedence over gap in maxWidth calculation
  • maxWidth with no gap — correctly calculates with 0px gap

Test plan

  • 11 new edge case tests all pass
  • All 29 tests pass (18 existing + 11 new)
  • Lint clean (no new warnings)

- Verify columns={0} falls back to 1fr default (not repeat(0, 1fr))
- Verify columns={-1} falls back to 1fr default
- Verify columns={0} with minChildWidth uses auto-fit without maxWidth cap
- Add tests for width/height props (numeric px and string pass-through)
- Add tests for minChildWidth + columnGap interaction (precedence over gap)
- Add test for maxWidth calculation with no gap specified
- Resolves P1 and P2 findings from hardening issue #719

Co-authored-by: Navi <[email protected]>
@cixzhang cixzhang added the hardening Component hardening and quality sweep label Mar 19, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 19, 2026
@github-actions

github-actions Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Grid · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 271B N/A
Lines of Code N/A 376 -
Complexity N/A High (23) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.7KB 17.0KB 2.6KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang merged commit 408b551 into main Mar 19, 2026
11 checks passed
@cixzhang
cixzhang deleted the navi/fix/grid-columns-guard branch March 19, 2026 21:34
cixzhang added a commit that referenced this pull request Apr 26, 2026
- Verify columns={0} falls back to 1fr default (not repeat(0, 1fr))
- Verify columns={-1} falls back to 1fr default
- Verify columns={0} with minChildWidth uses auto-fit without maxWidth cap
- Add tests for width/height props (numeric px and string pass-through)
- Add tests for minChildWidth + columnGap interaction (precedence over gap)
- Add test for maxWidth calculation with no gap specified
- Resolves P1 and P2 findings from hardening issue #719

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
- Verify columns={0} falls back to 1fr default (not repeat(0, 1fr))
- Verify columns={-1} falls back to 1fr default
- Verify columns={0} with minChildWidth uses auto-fit without maxWidth cap
- Add tests for width/height props (numeric px and string pass-through)
- Add tests for minChildWidth + columnGap interaction (precedence over gap)
- Add test for maxWidth calculation with no gap specified
- Resolves P1 and P2 findings from hardening issue #719

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
- Verify columns={0} falls back to 1fr default (not repeat(0, 1fr))
- Verify columns={-1} falls back to 1fr default
- Verify columns={0} with minChildWidth uses auto-fit without maxWidth cap
- Add tests for width/height props (numeric px and string pass-through)
- Add tests for minChildWidth + columnGap interaction (precedence over gap)
- Add test for maxWidth calculation with no gap specified
- Resolves P1 and P2 findings from hardening issue #719
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. hardening Component hardening and quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant