Skip to content

perf(widget): rename more private members in the minified builds, checked by a test - #453

Merged
anurag629 merged 1 commit into
devfrom
perf/widget-mangle
Oct 29, 2026
Merged

anurag629 merged 1 commit into
devfrom
perf/widget-mangle

Conversation

@anurag629

Copy link
Copy Markdown
Member

Makes room in the widget's size budget for #447 (the "New reply" pill, about 270 B), and for whatever comes after it. The panel was at 16.84 of 17 KB and the single file at 18.92 of 19 KB.

Bundle Before After Limit
Panel 16.84 kB 16.6 kB 17 kB
Single file 18.92 kB 18.62 kB 19 kB

Terser's property mangling renames a property everywhere in the bundle. That's safe for a private member, but a config field, a request body key (conversationId, messages), a stored field or a DOM property renamed by mistake breaks only the CDN build, and the unit tests run on src, so they'd miss it. That was my concern on #447. So instead of a longer hand-written regex:

  • packages/widget/mangle.ts holds the list, and both Vite configs import it. The 33 names from before (EARLIER) stay as they were. They're internal on both ends, and the e2e suite runs against the minified builds.
  • The 55 new names (CHECKED) are the private members that are only ever used as this.<name>. I found them by scanning src for every private member and dropping any that's accessed on another object, used as an object key or shorthand, written in a string, mentioned in api/widget.api.md, or two letters long. I also left out generic names like send, reset and emit.
  • tests/mangle.test.ts re-checks every CHECKED name on each run. It's declared private, only used through this, never a key or a string, not in the API snapshot, and not a property of window or the DOM prototypes the widget uses. Adding apiUrl, conversationId and reset to the list makes it fail.

CONTRIBUTING's widget section explains the list.

Tested: build, typecheck, test:coverage, lint (dev baseline), api:check and size pass. The full e2e suite passes in Chrome (69), and it loads the minified loader, panel and single-file builds.

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.

1 participant