perf: cut published package and partner-bundle bytes (YPE-5528) - #382
perf: cut published package and partner-bundle bytes (YPE-5528)#382cameronapak wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 010aedd The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dc137d2 to
f6bf5c9
Compare
| return ensureLocale(detected).then(() => { | ||
| if (i18n.language === detected) { | ||
| return detected; | ||
| } | ||
| return i18n.changeLanguage(detected).then(() => detected); | ||
| }); |
There was a problem hiding this comment.
If two non-English locale requests overlap, each continuation calls changeLanguage after its own import resolves without checking which locale was requested most recently. A slower older request can therefore overwrite the newer locale and leave SDK copy displayed in the wrong language.
Knowledge Base Used: React UI component library
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/i18n/index.ts
Line: 69-74
Comment:
**Stale locale requests win**
If two non-English locale requests overlap, each continuation calls `changeLanguage` after its own import resolves without checking which locale was requested most recently. A slower older request can therefore overwrite the newer locale and leave SDK copy displayed in the wrong language.
**Knowledge Base Used:** [React UI component library](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/react-ui.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| subscribeSdkLanguage((languageTag) => { | ||
| void syncSdkLanguage(languageTag); | ||
| }); | ||
| const pendingLocale = getRequestedSdkLanguage(); | ||
| if (pendingLocale.requested) { | ||
| void syncSdkLanguage(pendingLocale.languageTag); |
There was a problem hiding this comment.
If a non-English locale chunk cannot be fetched, ensureLocale rejects and these production call sites discard the promise without a rejection handler. This emits an unhandled promise rejection while leaving the requested language inactive, and runtimes configured to treat unhandled rejections as fatal can terminate the affected execution context.
Knowledge Base Used: React UI component library
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/i18n/index.ts
Line: 105-110
Comment:
**Locale load rejections escape**
If a non-English locale chunk cannot be fetched, `ensureLocale` rejects and these production call sites discard the promise without a rejection handler. This emits an unhandled promise rejection while leaving the requested language inactive, and runtimes configured to treat unhandled rejections as fatal can terminate the affected execution context.
**Knowledge Base Used:** [React UI component library](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/react-ui.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Stack 2/3 of #382. Hooks-only changes: deep imports of YouVersionContext, client-override fallback shape per hook, and query-key changes.
e82174e to
0803452
Compare
…d bytes (#384) * perf(core): split clients into tree-shakable modules and cut published bytes Stack 1/3 of #382. Core-only changes: module split into bible-*/languages-* files, zod-mini schemas, minified browser CSS, shared filtered paged-list helper, and the version-stamp check update. * chore(changeset): add core changeset for the tree-shakable module split * fix(core): restore expressive palette, chart, and sidebar theme tokens * refactor(core): move language and version options schemas into schemas/ * fix(core): centralize input schemas in schemas/ and restore page_size refine - Move client-module input schemas (version/book/chapter/verse ids, language id, organization id, highlight passage/color) into schemas/ so schemas stay the single source of truth; import schema files directly, not the barrel, to keep tree-shakable entries narrow - Restore the page_size="*" 1-3 fields refine on GetLanguagesOptionsSchema (dropped in the module split, replaced by an unreachable plain-Error check) - Dedupe BCP-47 regex and hex-color schema; type fetchFilteredCollection params - Document zod-mini $ZodError behavior note in the changeset; refresh core AGENTS.md STRUCTURE * fix(core): restore ui stamp, page_size Error, css watch, and ZodError identity Keep the changeset as patch. Restore the UI version-stamp entry so UI prepublishOnly still works, throw the prior page_size="*" Error message, watch core CSS into dist/styles during pnpm dev, and wrap Mini $ZodError at the public client boundary so instanceof ZodError still matches. * fix(core): drop ZodError wrap and document Mini $ZodError as patch Keep zod Mini as the public validation identity. Remove parsePublic and restore direct schema.parse(). Changeset stays patch and notes that schema failures throw $ZodError, not classic ZodError. page_size="*", UI stamp, and CSS watch stay as-is. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
… (YPE-5528) Stack 3/3 — UI dist split, i18n lazy locales, Storybook sheet loading, and the CI gates (tree-shaking UI row, size budgets, spec sentinels).
Stack 2/3 of #382. Hooks-only changes: deep imports of YouVersionContext, client-override fallback shape per hook, and query-key changes.
0803452 to
010aedd
Compare
Summary
distso a named import from the package root can drop unused Bible UI. No new public subpaths.BibleClient/LanguagesClientoff narrow hook graphs. Host client overrides still win.YPE-5528. Parent YPE-1193.
Size saved per import path
Minify + brotli, esbuild, no splitting. React, react-dom, jsx-runtime, react-query, and jsdom are external. Same ruler as
docs/ui-import-size-research.md.On
main(5ddc2e0), any one named UI import measured like Provider: 196.1 kB. The full barrel was 203.6 kB. The gap was 42 kB raw.@youversion/platform-react-uimain{ YouVersionProvider }{ BibleReader }{ BibleCard }{ Separator }import *full barrelNamed import from the root matches the component entry file. Do not add
./bible-reader.pnpm sizeon this branch (same no-split gate):mainbudget{ ApiClient }{ useChapter }{ YouVersionProvider }BibleReader stays large because of i18next, the full utility sheet, and passage/jsdom. Replacing i18next was considered and skipped. Provider already avoids that runtime.
Test plan
CI=true pnpm sizestays under the new budgetspnpm check:tree-shaking(Provider absent Bible reader/picker sentinels;useChapterabsentBibleClient/ jsdom)examples/vite-react: Provider-only page, then BibleReader + pickers, then Sign inrequire('@youversion/platform-react-ui')still resolveslocaleon Provider still translates missing-app-key copy without loading i18nextstyles.cssstill includes reader typographyGreptile Summary
The PR restructures the UI package to reduce consumer bundle size while preserving its root-level public API.
Confidence Score: 3/5
The PR does not yet appear safe to merge because locale changes can resolve to stale language state and failed locale chunks can emit unhandled rejections.
The two previously reported locale-loading defects remain at current HEAD: asynchronous catalog completion is not guarded by latest-request identity, and every production lazy-load path discards a promise whose rejection is not handled.
Files Needing Attention: packages/ui/src/i18n/index.ts and packages/ui/src/components/YouVersionProvider.tsx
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR App[Consumer import] --> Root[UI package root] Root --> Provider[YouVersionProvider entry] Root --> Components[Component entries] Provider --> Chrome[Chrome styles] Components --> Utilities[Component utility styles] Components --> I18n[i18next runtime] I18n --> English[English catalog] I18n --> Lazy[Lazy non-English catalogs] Components --> Reader[BibleTextView] Reader --> ReaderCSS[Reader typography]Reviews (3): Last reviewed commit: "chore(changeset): scope the UI split cha..." | Re-trigger Greptile