Skip to content

feat: report bundle size delta#2891

Open
jorgemoya wants to merge 8 commits intocanaryfrom
catalyst-1766-report-bundle-size-delta
Open

feat: report bundle size delta#2891
jorgemoya wants to merge 8 commits intocanaryfrom
catalyst-1766-report-bundle-size-delta

Conversation

@jorgemoya
Copy link
Contributor

@jorgemoya jorgemoya commented Feb 19, 2026

What/Why?

This feature adds automated bundle size tracking to the CI pipeline. Every time a PR is opened or updated, the build is compiled and its output is compared against a stored baseline snapshot, with the size differences posted as a PR comment. To keep that baseline from going stale, a separate workflow automatically regenerates and commits it whenever code is merged into canary or integrations/makeswift.

Testing

Bundle reporting tested below. Testing the workflow to keep baseline is sync is TBD.

Migration

N/A

@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
catalyst Ready Ready Preview, Comment Feb 19, 2026 9:14pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

⚠️ No Changeset found

Latest commit: 5e95cc6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Bundle Size Report

Comparing against baseline from a161583fe (2026-02-18).

Per-Route First Load JS

Route Baseline Current Delta
/(default)/(auth)/login/page 314.7 kB 314.8 kB +0.1 kB (+0%)
/(default)/(auth)/register/page 351.4 kB 351.5 kB +0.1 kB (+0%)
/(default)/(faceted)/category/[slug]/page 334.4 kB 334.5 kB +0.1 kB (+0%)
/(default)/account/orders/[id]/page 316.9 kB 317 kB +0.1 kB (+0%)
/(default)/account/wishlists/page 328.5 kB 328.6 kB +0.1 kB (+0%)
/(default)/compare/page 318 kB 318.1 kB +0.1 kB (+0%)
/(default)/product/[slug]/page 378.5 kB 378.4 kB -0.1 kB (0%)

Threshold: 5% increase. Routes with ⚠️ exceed the threshold.

@jorgemoya jorgemoya marked this pull request as ready for review February 19, 2026 16:31
@jorgemoya jorgemoya requested a review from a team as a code owner February 19, 2026 16:31
Comment on lines 18 to 24
function getFlag(name, defaultValue) {
const idx = args.indexOf(`--${name}`);

if (idx === -1 || idx + 1 >= args.length) return defaultValue;

return args[idx + 1];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to us this!

Comment on lines 50 to 59
function getCommitSha() {
try {
return execSync('git rev-parse --short HEAD', {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
} catch {
return 'unknown';
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 Since HEAD is hardcoded (assuming you won't be using this to get the sha of any other commit), you can probably just use github.sha (docs) in the Action and pass it to your script like

run: node .github/scripts/bundle-size.mjs generate --output .github/bundle-baseline.json --sha ${{ github.sha }} 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

Comment on lines +361 to +377
if (command === 'generate') {
generate();
} else if (command === 'compare') {
compare();
} else {
console.error('Usage: bundle-size.mjs <generate|compare> [options]');
console.error('');
console.error('Commands:');
console.error(' generate Analyze .next/ build output and produce bundle size JSON');
console.error(' --output <path> Write JSON to file instead of stdout');
console.error('');
console.error(' compare Compare current bundle against a baseline');
console.error(' --baseline <path> Path to baseline JSON (default: ./bundle-baseline.json)');
console.error(' --current <path> Path to current bundle JSON (required)');
console.error(' --threshold <n> Warning threshold percentage (default: 5)');
process.exit(1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

command is now parsed via parseArgs. Or where you thinking something else?

Comment on lines 59 to 85
const fs = require('fs');
const marker = '<!-- bundle-size-report -->';
const body = marker + '\n' + fs.readFileSync('/tmp/bundle-report.md', 'utf-8');

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const existing = comments.find(c => c.body.includes(marker));

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not have this in a JS file that we can reference by path here? Does the @actions/github-script action support providing a path to the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout. Split to a JS file.

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.

4 participants

Comments