Skip to content

feat(core): format-bytes - #205

Open
coryrylan wants to merge 2 commits into
mainfrom
topic-format-bytes
Open

feat(core): format-bytes#205
coryrylan wants to merge 2 commits into
mainfrom
topic-format-bytes

Conversation

@coryrylan

@coryrylan coryrylan commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator
  • Introduced nve-format-bytes component to convert byte counts into human-readable decimal or binary units

Summary by CodeRabbit

  • New Features

    • Added a Format Bytes element for displaying byte values in decimal or binary units.
    • Supports automatic or fixed units, short or long labels, locale formatting, and precision controls.
    • Accepts numeric values or text content, with graceful handling of invalid inputs.
    • Available through the main component bundle and as a standalone custom element.
  • Documentation

    • Added installation guidance, usage examples, and navigation for the new element.
  • Tests

    • Added accessibility, performance, server-rendering, visual, and functional coverage.

@coryrylan
coryrylan requested a review from johnyanarella July 31, 2026 22:52
@coryrylan coryrylan self-assigned this Jul 31, 2026
Copilot AI lite review requested due to automatic review settings July 31, 2026 22:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added scope(core) scope(docs) dependencies Pull requests that update a dependency file labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds the FormatBytes Lit component. It supports locale-aware decimal and binary formatting, configurable units, labels, precision, and value sources. It also adds public exports, custom-element registration, tests, Storybook examples, bundle validation, and documentation.

Changes

Format Bytes component

Layer / File(s) Summary
Formatting component and rendering
projects/core/src/format-bytes/format-bytes.ts, projects/core/src/format-bytes/format-bytes.css
FormatBytes validates inputs, formats values with locale and precision, renders <data> output, updates slot fallback content, and applies styling.
Custom-element registration and package exposure
projects/core/src/format-bytes/define.ts, projects/core/src/format-bytes/index.ts, projects/core/package.json, projects/core/src/bundle.ts
The nve-format-bytes element is registered and added to package exports, bundle imports, and public exports.
Examples and component validation
projects/core/src/format-bytes/*examples.ts, projects/core/src/format-bytes/*test*, projects/core/src/index.test.lighthouse.ts
Examples and tests cover formatting options, SSR output, accessibility, Lighthouse scores, visual themes, and bundle size.
Documentation site integration
projects/site/src/_11ty/layouts/common.js, projects/site/src/docs/elements/format-bytes.md
The site navigation and documentation page describe the new element and its supported options.

Repository validation and maintenance

Layer / File(s) Summary
Bundle and Lighthouse registration validation
projects/core/eslint.config.js, projects/internals/eslint/src/local/no-missing-bundle-registration.*
The ESLint rule checks that bundle components also have direct imports in the aggregate Lighthouse test.
Workflow and fixture maintenance
.agents/skills/component-creation/SKILL.md, projects/core/src/internal/utils/keynav.test.ts, projects/internals/eslint/src/configs/lit.js
Workflow guidance covers bundle and Lighthouse updates. Key navigation tests use shared fixtures. Lit ESLint configuration removes obsolete exclusions.
Element status filtering
projects/site/src/docs/metrics/api-status.11ty.js, config/vale/styles/config/vocabularies/Elements/accept.txt
Element status filtering retains json-viewer, and its vocabulary entry is removed.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant FormatBytes
  participant IntlNumberFormat
  Consumer->>FormatBytes: Set value and formatting properties
  FormatBytes->>IntlNumberFormat: Format value with locale and precision
  IntlNumberFormat-->>FormatBytes: Return localized number
  FormatBytes-->>Consumer: Render formatted value and unit label
Loading

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: adding the core format-bytes component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch topic-format-bytes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/core/src/format-bytes/format-bytes.test.axe.ts`:
- Around line 13-26: Update the stability setup in the test around
FormatBytes.metadata.tag to await elementIsStable for all three nve-format-bytes
fixture elements, rather than only the first querySelector result, before
calling runAxe. Preserve the existing fixture cleanup and accessibility
assertion.

In `@projects/core/src/format-bytes/format-bytes.ts`:
- Around line 130-146: Make display sourcing consistent between `#resolveAutoUnit`
and `#formatLabel`. Prefer passing the display value explicitly by updating
`#formatLabel` to accept a display parameter and updating its call in
`#formattedBytes` to pass this.display, while using that parameter for label
selection.
- Around line 148-167: Update `#warnInvalidOption` to remove the rawValue
parameter and return type/value, then adjust its callers in
`#hasValidConfiguration` to pass only the option name and value. Remove rawValue
from `#hasValidConfiguration` as well, and update its call site to invoke it
without arguments while preserving the existing invalid-configuration return
behavior.
- Around line 142-146: Update the formatting flow around `#formattedBytes` and
`#formatLabel` so the value is rounded once using the same fraction-digit settings
as `#formatNumber`, then pass that rounded value to both helpers. Select singular
versus plural in `#formatLabel` based on the rounded value while preserving
short-label behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: b30e9a98-6f6c-4e84-ac6e-c5b9e9faad96

📥 Commits

Reviewing files that changed from the base of the PR and between 651abf3 and b57257b.

⛔ Files ignored due to path filters (2)
  • projects/core/.visual/format-bytes.dark.png is excluded by !**/*.png
  • projects/core/.visual/format-bytes.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • projects/core/package.json
  • projects/core/src/bundle.ts
  • projects/core/src/format-bytes/define.ts
  • projects/core/src/format-bytes/format-bytes.css
  • projects/core/src/format-bytes/format-bytes.examples.ts
  • projects/core/src/format-bytes/format-bytes.test.axe.ts
  • projects/core/src/format-bytes/format-bytes.test.lighthouse.ts
  • projects/core/src/format-bytes/format-bytes.test.ssr.ts
  • projects/core/src/format-bytes/format-bytes.test.ts
  • projects/core/src/format-bytes/format-bytes.test.visual.ts
  • projects/core/src/format-bytes/format-bytes.ts
  • projects/core/src/format-bytes/index.ts
  • projects/core/src/index.test.lighthouse.ts
  • projects/site/src/_11ty/layouts/common.js
  • projects/site/src/docs/elements/format-bytes.md

Comment thread projects/core/src/format-bytes/format-bytes.test.axe.ts Outdated
Comment thread projects/core/src/format-bytes/format-bytes.ts
Comment thread projects/core/src/format-bytes/format-bytes.ts
Comment thread projects/core/src/format-bytes/format-bytes.ts Outdated
Copilot AI review requested due to automatic review settings August 4, 2026 14:31
@coryrylan
coryrylan force-pushed the topic-format-bytes branch from b57257b to 351a0f2 Compare August 4, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/core/src/index.test.lighthouse.ts`:
- Line 18: The FormatBytes component definition import is missing from the
js-modules list used in the benchmark, so the new component is not included in
the aggregate payload measurement. Add the
`@nvidia-elements/core/format-bytes/define.js` import to the module-import list in
the test setup. After adding the import, run the benchmark to measure the actual
payload. Update the 134.5 KB threshold in the expect assertion only if the
measured payload for index.js exceeds the current limit.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 660ec1ed-b543-4228-96dd-5fab6d84b4ae

📥 Commits

Reviewing files that changed from the base of the PR and between b57257b and 351a0f2.

⛔ Files ignored due to path filters (2)
  • projects/core/.visual/format-bytes.dark.png is excluded by !**/*.png
  • projects/core/.visual/format-bytes.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • projects/core/package.json
  • projects/core/src/bundle.ts
  • projects/core/src/format-bytes/define.ts
  • projects/core/src/format-bytes/format-bytes.css
  • projects/core/src/format-bytes/format-bytes.examples.ts
  • projects/core/src/format-bytes/format-bytes.test.axe.ts
  • projects/core/src/format-bytes/format-bytes.test.lighthouse.ts
  • projects/core/src/format-bytes/format-bytes.test.ssr.ts
  • projects/core/src/format-bytes/format-bytes.test.ts
  • projects/core/src/format-bytes/format-bytes.test.visual.ts
  • projects/core/src/format-bytes/format-bytes.ts
  • projects/core/src/format-bytes/index.ts
  • projects/core/src/index.test.lighthouse.ts
  • projects/site/src/_11ty/layouts/common.js
  • projects/site/src/docs/elements/format-bytes.md

Comment thread projects/core/src/index.test.lighthouse.ts
@property({ type: Number, attribute: 'maximum-fraction-digits' }) maximumFractionDigits?: number;

get #rawValue(): string {
if (this.value === undefined) return this.textContent?.trim() ?? '';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

|| this.value === null)

Lit will set value to null if the value attribute is removed. Without this check, the component skips this branch and renders "null" instead of the text fallback.

(The other formatter components handle this with a nullish fallback.)

- Introduced `nve-format-bytes` component to convert byte counts into human-readable decimal or binary units

Signed-off-by: Cory Rylan <crylan@nvidia.com>
- Updated the component creation guide to include new steps for updating shared entry points and measuring payloads.
- Modified ESLint rules to enforce bundle registration and added support for Lighthouse benchmark integration.
- Expanded Lighthouse test imports to include additional components and adjusted payload size expectations.
- Removed deprecated component from vocabulary list and updated related documentation.

Signed-off-by: Cory Rylan <crylan@nvidia.com>
Copilot AI review requested due to automatic review settings August 5, 2026 22:46
@coryrylan
coryrylan force-pushed the topic-format-bytes branch from 351a0f2 to c46c74d Compare August 5, 2026 22:46
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Suppressed comments (1)

projects/core/src/format-bytes/format-bytes.ts:111

  • When value is provided via the attribute and is not a valid number (e.g. value="not-a-number"), Lit's Number converter sets this.value to NaN. The current #rawValue then becomes 'NaN', so the component both warns about and renders NaN rather than preserving the original input string (unlike invalid slot content, and unlike format-number which preserves invalid attribute text).
  get #rawValue(): string {
    return String(this.value ?? this.textContent?.trim() ?? '');
  }

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/internals/eslint/src/local/no-missing-bundle-registration.js`:
- Around line 153-159: In no-missing-bundle-registration.js, replace raw-text
lighthouse import matching with AST-based collection of only static
ImportDeclaration module specifiers, preserving extraction of the component name
from valid `${escapedPrefix}/<component>/define.js` imports. In
projects/internals/eslint/src/local/no-missing-bundle-registration.test.js lines
109-137, add coverage proving matching text in comments or string literals still
reports missing-lighthouse-registration.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 371bf729-2dbd-48c2-8432-5470988dba19

📥 Commits

Reviewing files that changed from the base of the PR and between 0b24dcc and c46c74d.

⛔ Files ignored due to path filters (2)
  • projects/core/.visual/format-bytes.dark.png is excluded by !**/*.png
  • projects/core/.visual/format-bytes.png is excluded by !**/*.png
📒 Files selected for processing (23)
  • .agents/skills/component-creation/SKILL.md
  • config/vale/styles/config/vocabularies/Elements/accept.txt
  • projects/core/eslint.config.js
  • projects/core/package.json
  • projects/core/src/bundle.ts
  • projects/core/src/format-bytes/define.ts
  • projects/core/src/format-bytes/format-bytes.css
  • projects/core/src/format-bytes/format-bytes.examples.ts
  • projects/core/src/format-bytes/format-bytes.test.axe.ts
  • projects/core/src/format-bytes/format-bytes.test.lighthouse.ts
  • projects/core/src/format-bytes/format-bytes.test.ssr.ts
  • projects/core/src/format-bytes/format-bytes.test.ts
  • projects/core/src/format-bytes/format-bytes.test.visual.ts
  • projects/core/src/format-bytes/format-bytes.ts
  • projects/core/src/format-bytes/index.ts
  • projects/core/src/index.test.lighthouse.ts
  • projects/core/src/internal/utils/keynav.test.ts
  • projects/internals/eslint/src/configs/lit.js
  • projects/internals/eslint/src/local/no-missing-bundle-registration.js
  • projects/internals/eslint/src/local/no-missing-bundle-registration.test.js
  • projects/site/src/_11ty/layouts/common.js
  • projects/site/src/docs/elements/format-bytes.md
  • projects/site/src/docs/metrics/api-status.11ty.js
💤 Files with no reviewable changes (2)
  • config/vale/styles/config/vocabularies/Elements/accept.txt
  • projects/internals/eslint/src/configs/lit.js

Comment on lines +153 to +159
const lighthouseSource = readFileSync(lighthouseTestPath, 'utf8');
const lighthouseImportPattern = new RegExp(`${escapedPrefix}/([^/]+)/define\\.js`, 'g');
const lighthouseComponents = new Set();

for (const match of lighthouseSource.matchAll(lighthouseImportPattern)) {
if (match[1]) lighthouseComponents.add(match[1]);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Parse Lighthouse imports as syntax, not raw text.

The regular expression accepts matching text in comments and string literals. A comment containing @nvidia-elements/core/card/define.js can add card to lighthouseComponents, so the bundle registration passes without a direct benchmark import.

  • projects/internals/eslint/src/local/no-missing-bundle-registration.js#L153-L159: collect only static ImportDeclaration module specifiers.
  • projects/internals/eslint/src/local/no-missing-bundle-registration.test.js#L109-L137: add a case where matching comment or string text still reports missing-lighthouse-registration.
🧰 Tools
🪛 ast-grep (0.45.0)

[warning] 153-153: Detects non-literal values in regular expressions
Context: new RegExp(${escapedPrefix}/([^/]+)/define\\.js, 'g')
Note: [CWE-1333] Inefficient Regular Expression Complexity (ReDoS via non-literal RegExp).

(detect-non-literal-regexp)

📍 Affects 2 files
  • projects/internals/eslint/src/local/no-missing-bundle-registration.js#L153-L159 (this comment)
  • projects/internals/eslint/src/local/no-missing-bundle-registration.test.js#L109-L137
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/internals/eslint/src/local/no-missing-bundle-registration.js` around
lines 153 - 159, In no-missing-bundle-registration.js, replace raw-text
lighthouse import matching with AST-based collection of only static
ImportDeclaration module specifiers, preserving extraction of the component name
from valid `${escapedPrefix}/<component>/define.js` imports. In
projects/internals/eslint/src/local/no-missing-bundle-registration.test.js lines
109-137, add coverage proving matching text in comments or string literals still
reports missing-lighthouse-registration.

@johnyanarella
johnyanarella self-requested a review August 5, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants