Skip to content

[code-infra] Setup error message minification #1463

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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Feb 18, 2025

Port core error minification infrastructure:

Copy link

netlify bot commented Feb 19, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 8e6427d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/683866ecde0dc70008307889
😎 Deploy Preview https://deploy-preview-1463--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Janpot Janpot changed the title [code-infra] Initial setup for minified error messages (WIP) [code-infra] Setup error message minification Feb 20, 2025
@Janpot Janpot marked this pull request as ready for review February 20, 2025 17:43
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 3, 2025
@Janpot Janpot self-assigned this Mar 13, 2025
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

It looks good, aside from a typo I found.
@atomiks, do you see anything missing from this implementation?

In the future, we could create an error throw helper function to ensure consistency in our messages.
I'm wondering how big the bundle size savings will be and if the minification is really worth the hassle.

…isplay.tsx

Co-authored-by: Michał Dudak <[email protected]>
Signed-off-by: Jan Potoms <[email protected]>
@Janpot
Copy link
Member Author

Janpot commented Mar 20, 2025

I'm wondering how big the bundle size savings will be and if the minification is really worth the hassle.

Ideally we'd have the bundle size checker in base repo. I can fix that up and port next? We could also postpone merging this PR until then if you want,

Janpot and others added 2 commits March 20, 2025 03:01
@michaldudak
Copy link
Member

michaldudak commented Mar 20, 2025

I checked it manually and it turns out that this PR (with the lastest master merged in) produces a larger package than what's on master.

I ran pnpm build and pnpm pack in the package directory with the following results:

This PR:
package (tgz): 332555 bytes
esm directory (unpacked): 1315505 bytes

master:
package (tgz): 329511 bytes (3044 bytes less)
esm directory (unpacked): 1307340 bytes (8165 bytes less)

I expect it to look different when we add more components and have more error messages, but for now there seems to be no point in making this change (unless my methodology is wrong).

We can also have additional gains in the minifier-less implementation by creating the error helper I mentioned in #1463 (review)

@Janpot
Copy link
Member Author

Janpot commented Mar 20, 2025

(unless my methodology is wrong)

The installed size will indeed be larger as it contains a new function and the error codes alongside the dev messages. But that's not what ends up in user's applications. You need to bundle the package with process.env.NODE_ENV set to 'production' and check the result. That's why I proposed we clean up and port the bundle size checker from core.

@Janpot Janpot added the on hold There is a blocker; we need to wait label Mar 20, 2025
@Janpot
Copy link
Member Author

Janpot commented Mar 20, 2025

Putting this on hold until we've ported the bundle size checker and can assess the impact.

@michaldudak michaldudak added scope: code-infra Specific to the code-infra product and removed scope: code-infra labels May 22, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 29, 2025
Copy link

pkg-pr-new bot commented May 29, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@base-ui-components/react@1463

commit: 8e6427d

@mui-bot
Copy link

mui-bot commented May 29, 2025

Bundle size report

Total Size Change:${\tiny{\color{green}▼}}$-9.42KB(-0.65%) - Total Gzip Change:${\tiny{\color{green}▼}}$-778B(-0.16%)
Files: 41 total (0 added, 0 removed, 36 changed)

@base-ui-components/react/separatorparsed:${\tiny{\color{red}▲}}$+150B(+3.50%) gzip:${\tiny{\color{red}▲}}$+101B(+5.50%)
@base-ui-components/reactparsed:${\tiny{\color{green}▼}}$-4.71KB(-1.54%) gzip:${\tiny{\color{green}▼}}$-741B(-0.80%)
@base-ui-components/react/menuparsed:${\tiny{\color{green}▼}}$-800B(-0.70%) gzip:${\tiny{\color{green}▼}}$-145B(-0.38%)
@base-ui-components/react/context-menuparsed:${\tiny{\color{green}▼}}$-753B(-0.67%) gzip:${\tiny{\color{green}▼}}$-147B(-0.40%)
@base-ui-components/react/selectparsed:${\tiny{\color{green}▼}}$-513B(-0.46%) gzip:${\tiny{\color{green}▼}}$-67B(-0.18%)
@base-ui-components/react/navigation-menuparsed:${\tiny{\color{green}▼}}$-366B(-0.43%) gzip:${\tiny{\color{green}▼}}$-35B(-0.12%)
@base-ui-components/react/accordionparsed:${\tiny{\color{green}▼}}$-307B(-1.33%) gzip:${\tiny{\color{green}▼}}$-27B(-0.34%)

Show 29 more bundle changes

@base-ui-components/react/fieldsetparsed:${\tiny{\color{red}▲}}$+150B(+2.53%) gzip:${\tiny{\color{red}▲}}$+89B(+3.60%)
@base-ui-components/react/use-renderparsed:${\tiny{\color{red}▲}}$+150B(+3.91%) gzip:${\tiny{\color{red}▲}}$+99B(+5.94%)
@base-ui-components/react/formparsed:${\tiny{\color{red}▲}}$+111B(+1.93%) gzip:${\tiny{\color{red}▲}}$+77B(+3.13%)
@base-ui-components/react/meterparsed:${\tiny{\color{red}▲}}$+71B(+0.96%) gzip:${\tiny{\color{red}▲}}$+46B(+1.52%)
@base-ui-components/react/progressparsed:${\tiny{\color{red}▲}}$+62B(+0.83%) gzip:${\tiny{\color{red}▲}}$+42B(+1.38%)
@base-ui-components/react/menubarparsed:${\tiny{\color{red}▲}}$+35B(+0.18%) gzip:${\tiny{\color{red}▲}}$+28B(+0.38%)
@base-ui-components/react/inputparsed:${\tiny{\color{red}▲}}$+34B(+0.31%) gzip:${\tiny{\color{red}▲}}$+19B(+0.43%)
@base-ui-components/react/checkbox-groupparsed:${\tiny{\color{red}▲}}$+31B(+0.26%) gzip:${\tiny{\color{red}▲}}$+15B(+0.31%)
@base-ui-components/react/fieldparsed:${\tiny{\color{red}▲}}$+31B(+0.23%) gzip:${\tiny{\color{red}▲}}$+17B(+0.32%)
@base-ui-components/react/avatarparsed:${\tiny{\color{red}▲}}$+25B(+0.35%) gzip:${\tiny{\color{red}▲}}$+24B(+0.83%)
@base-ui-components/react/number-fieldparsed:${\tiny{\color{green}▼}}$-284B(-0.98%) gzip:${\tiny{\color{green}▼}}$-21B(-0.20%)
@base-ui-components/react/checkboxparsed:${\tiny{\color{green}▼}}$-254B(-1.36%) gzip:${\tiny{\color{green}▼}}$-22B(-0.31%)
Base UI checkboxparsed:${\tiny{\color{green}▼}}$-254B(-1.36%) gzip:${\tiny{\color{green}▼}}$-21B(-0.30%)
@base-ui-components/react/popoverparsed:${\tiny{\color{green}▼}}$-242B(-0.28%) gzip:${\tiny{\color{green}▼}}$-8B(-0.03%)
@base-ui-components/react/scroll-areaparsed:${\tiny{\color{green}▼}}$-241B(-1.53%) gzip:${\tiny{\color{green}▼}}$-17B(-0.30%)
@base-ui-components/react/tabsparsed:${\tiny{\color{green}▼}}$-177B(-0.74%) gzip:${\tiny{\color{green}▼}}$-1B(-0.01%)
@base-ui-components/react/preview-cardparsed:${\tiny{\color{green}▼}}$-162B(-0.27%) gzip:${\tiny{\color{green}▼}}$-49B(-0.24%)
@base-ui-components/react/toolbarparsed:${\tiny{\color{green}▼}}$-161B(-0.82%) gzip:${\tiny{\color{red}▲}}$+8B(+0.12%)
@base-ui-components/react/switchparsed:${\tiny{\color{green}▼}}$-149B(-1.02%) gzip:${\tiny{\color{green}▼}}$-15B(-0.27%)
@base-ui-components/react/tooltipparsed:${\tiny{\color{green}▼}}$-147B(-0.23%) gzip:${\tiny{\color{green}▼}}$-40B(-0.18%)
@base-ui-components/react/radioparsed:${\tiny{\color{green}▼}}$-145B(-0.97%) gzip: 0B(0.00%)
@base-ui-components/react/toastparsed:${\tiny{\color{green}▼}}$-126B(-0.48%) gzip:${\tiny{\color{green}▼}}$-13B(-0.14%)
@base-ui-components/react/alert-dialogparsed:${\tiny{\color{green}▼}}$-121B(-0.23%) gzip:${\tiny{\color{green}▼}}$-12B(-0.07%)
@base-ui-components/react/sliderparsed:${\tiny{\color{green}▼}}$-96B(-0.39%) gzip:${\tiny{\color{green}▼}}$-8B(-0.09%)
@base-ui-components/react/dialogparsed:${\tiny{\color{green}▼}}$-93B(-0.18%) gzip:${\tiny{\color{red}▲}}$+3B(+0.02%)
@base-ui-components/react/collapsibleparsed:${\tiny{\color{green}▼}}$-83B(-0.46%) gzip:${\tiny{\color{red}▲}}$+9B(+0.14%)
@base-ui-components/react/toggleparsed:${\tiny{\color{green}▼}}$-75B(-0.83%) gzip:${\tiny{\color{red}▲}}$+4B(+0.11%)
@base-ui-components/react/toggle-groupparsed:${\tiny{\color{green}▼}}$-5B(-0.04%) gzip:${\tiny{\color{red}▲}}$+16B(+0.30%)
@base-ui-components/react/radio-groupparsed:${\tiny{\color{green}▼}}$-2B(-0.01%) gzip:${\tiny{\color{red}▲}}$+14B(+0.18%)

Details of bundle changes

Generated by 🚫 dangerJS against 8e6427d

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 2, 2025
@michaldudak
Copy link
Member

Since the bundle size checker is running, we can continue with this. The size saving aren't enormous (-0.80% gzipped for the whole library), but they might get slightly more significant as we create more components that throw more errors. I tested an alternative approach, but it's much worse: #2050

One additional thing we need here is for the build to fail if error messages haven't been extracted.

@Janpot
Copy link
Member Author

Janpot commented Jun 3, 2025

but they might get slightly more significant as we create more components that throw more errors.

It would also enable more verbose error messages for a better DX. in case you were holding back atm 🙂. We can keep this on hold for a bit longer as well as far as I'm concerned to let the lib get a little more stable.

One additional thing we need here is for the build to fail if error messages haven't been extracted.

Currently CI should fail by checking changes, do you want to build this into the build step directly?

@michaldudak
Copy link
Member

in case you were holding back atm 🙂

No, that's fine :) There are size savings already, so we can move forward with this. I'd like to merge #2049 first, though, so the messages are consistent.

Currently CI should fail by checking changes

OK, that's enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold There is a blocker; we need to wait PR: out-of-date The pull request has merge conflicts and can't be merged scope: code-infra Specific to the code-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants