Skip to content

perf(hooks): deep-import context and keep core clients off narrow graphs - #385

Open
cameronapak wants to merge 4 commits into
mainfrom
cp/hooks-split
Open

perf(hooks): deep-import context and keep core clients off narrow graphs#385
cameronapak wants to merge 4 commits into
mainfrom
cp/hooks-split

Conversation

@cameronapak

@cameronapak cameronapak commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Deep-import the hooks context and use narrow core request functions so single-hook imports can tree-shake unrelated clients and Auth.
  • Preserve provider client overrides and keep the lazy auth component identity stable with a module-cached getter initialized only by the auth-enabled branch.
  • Enable Rollup tree-shaking, clean stale build output, and remove the now-orphaned internal language client helper.
  • Add consumer-shaped Auth leakage enforcement and ratchet the useChapter bundle budget from 64 kB to 12.2 kB.

YPE-5528. No public API change.

Bundle result

After a forced build, hooks / useChapter only measures 11.06 kB Brotli with React, React DOM, TanStack Query, and jsdom externalized. The 12.2 kB gate provides about 10% headroom.

The tree-shaking check proves the narrow bundle excludes the Auth granted-permissions storage sentinel while the auth control bundle includes it.

Stack

#384 is merged. #382 remains based on this PR and should merge after it.

Verification

  • pnpm exec turbo build --force
  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm size
  • pnpm check:tree-shaking

— Cursor, an AI agent sent on behalf of Cam

Greptile Summary

The PR narrows individual hook dependency graphs while preserving client overrides and the public package API.

  • Deep-imports YouVersionContext to avoid evaluating the context barrel and auth code for narrow hook imports.
  • Uses core API functions when no provider client override is supplied.
  • Enables tsup tree-shaking, tightens the bundle-size limit, and cleans stale declaration artifacts before builds.
  • Adds the required patch changeset and stabilizes lazy auth-provider identity at module scope.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported lazy-auth identity issue and missing changeset have both been fixed.

Important Files Changed

Filename Overview
packages/hooks/src/context/YouVersionProvider.tsx Caches the lazy auth provider at module scope, resolving the previously reported identity instability across Suspense retries.
.changeset/ype-5528-hooks-split.md Adds the required patch release record for the hooks package.
packages/hooks/tsup.config.ts Centralizes the hooks build entries and enables Rollup tree-shaking with conservative whitespace minification.
packages/hooks/package.json Uses the tsup configuration, cleans dist before building, and excludes stale declaration artifacts from publication.
packages/hooks/src/useChapter.ts Preserves injected BibleClient behavior while using the narrower core getChapter function as the default path.
packages/hooks/src/useLanguage.ts Preserves injected LanguagesClient behavior while using the narrower core getLanguage function as the default path.
scripts/check-tree-shaking.mjs Extends bundle assertions to verify auth permission-storage code remains absent from narrow hook graphs.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Consumer[Consumer imports one hook] --> Hook[Individual React hook]
  Hook --> Context[YouVersionContext module]
  Hook --> Override{Client override supplied?}
  Override -->|Yes| Client[Injected client method]
  Override -->|No| Function[Core API function]
  Context -. auth excluded from narrow graph .-> Bundle[Tree-shaken bundle]
  Client --> API[Platform API]
  Function --> API
Loading

Reviews (6): Last reviewed commit: "fix(hooks): address narrow bundle review..." | Re-trigger Greptile

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 421ecdf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-react-hooks Patch
@youversion/platform-react-ui Patch
vite-react Patch
@youversion/platform-core Patch

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

Comment thread packages/hooks/src/context/YouVersionProvider.tsx Outdated
Comment thread packages/hooks/package.json
Base automatically changed from cp/core-split to main September 9, 2026 18:59
Stack 2/3 of #382. Hooks-only changes: deep imports of YouVersionContext,
client-override fallback shape per hook, and query-key changes.
Comment thread packages/hooks/src/context/YouVersionProvider.tsx Outdated
Comment thread packages/hooks/tsup.config.ts
Comment thread packages/hooks/src/useChapter.test.tsx Outdated
Comment thread packages/hooks/src/useLanguage.test.tsx Outdated
Comment thread packages/hooks/src/useLanguageClient.ts Outdated
Comment thread packages/hooks/src/context/YouVersionProvider.tsx
Comment thread packages/hooks/src/internal/versionFilterKey.ts Outdated
Comment thread packages/hooks/tsup.config.ts Outdated
@cameronapak
cameronapak requested a review from abharms September 11, 2026 15:47
@cameronapak

Copy link
Copy Markdown
Collaborator Author

Ready for re-review @abharms! Thanks for the initial review!

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.

2 participants