Skip to content

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

Open
cameronapak wants to merge 2 commits into
cp/core-splitfrom
cp/hooks-split
Open

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

Conversation

@cameronapak

@cameronapak cameronapak commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Stack 2/3 — on top of #384. Parent: #382.

What

  • Hooks deep-import ./context/YouVersionContext instead of the barrel, so a single-hook import stays narrow
  • Per-hook client-override fallback shape (bibleClient ? bibleClient.getX(...) : getX(apiClient, ...)) keeps BibleClient / LanguagesClient classes off narrow hook graphs
  • Consistent bibleClient naming for the context override

Why

A partner importing useChapter pays ~10 KB instead of the full barrel.

Verification

  • pnpm build --force, pnpm typecheck, pnpm test (320 hooks tests) pass on this branch — with main's ui, proving hooks back-compat
  • No public API change

Merge second of the stack (after #384, then #382).

— Cursor, an AI agent sent on behalf of Cam

Greptile Summary

The PR narrows individual hook dependency graphs while preserving optional context-provided client overrides, and updates the hooks build and publication configuration.

  • Deep-imports YouVersionContext to avoid evaluating its barrel.
  • Uses core request functions when no service-client override is provided.
  • Enables tsup tree shaking, cleans stale build output, and excludes unwanted declaration artifacts.
  • Adds the required patch changeset.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains established.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/hooks/src/context/YouVersionProvider.tsx Introduces a dedicated lazy authentication gate; the available evidence does not conclusively establish whether its memoized component identity survives initial-suspension retries.
packages/hooks/package.json Moves JS builds to tsup configuration, cleans output before building, and excludes stale declaration artifacts from publication.
packages/hooks/tsup.config.ts Defines the hooks package entry points, formats, tree shaking, externals, and whitespace-only minification.
packages/hooks/src/useChapter.ts Preserves context client overrides while using the core request function for the narrow default graph.
packages/hooks/src/useLanguage.ts Preserves language-client overrides while using the core request function when no override exists.
.changeset/ype-5528-hooks-split.md Supplies the required patch release intent for the published hooks changes.

Reviews (2): Last reviewed commit: "chore(changeset): add hooks changeset fo..." | Re-trigger Greptile

Context used (3)

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ce029a2

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

config: { appKey: string; apiHost?: string; redirectUri: string };
userInfo?: YouVersionUserInfoJSON | null;
children: ReactNode;
}): React.ReactElement {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Lazy auth identity is unstable

When an auth-enabled provider initially suspends while loading YouVersionAuthProvider, React can discard the gate's useMemo cache and create another uninitialized lazy component on retry, leaving the application behind the empty Suspense fallback instead of mounting its children.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/context/YouVersionProvider.tsx
Line: 81

Comment:
**Lazy auth identity is unstable**

When an auth-enabled provider initially suspends while loading `YouVersionAuthProvider`, React can discard the gate's `useMemo` cache and create another uninitialized lazy component on retry, leaving the application behind the empty `Suspense` fallback instead of mounting its children.

**Knowledge Base Used:**
- [Hook providers and authentication state](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/hooks-providers-auth.md)
- [React hooks integration](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/react-hooks.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Cursor Fix in Codex

Comment on lines +43 to +46
"dev": "tsup --watch",
"build:js": "tsup",
"build:types": "tsc -p tsconfig.build.json",
"build": "pnpm build:js && pnpm build:types",
"build": "rm -rf dist && pnpm build:js && pnpm build:types",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Published changes lack a changeset

This PR changes the published hooks package without adding a normal or empty changeset, causing the repository's release-intent check to fail and block the pull request.

Context Used: Enforce project-specific review guidelines - see d... (source)

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/package.json
Line: 43-46

Comment:
**Published changes lack a changeset**

This PR changes the published hooks package without adding a normal or empty changeset, causing the repository's release-intent check to fail and block the pull request.

**Context Used:** Enforce project-specific review guidelines - see d... ([source](https://github.com/youversion/platform-sdk-react/blob/86177c4d12fd427c2bebb5ffefc5d5d67047be66/greptile.json))

**Knowledge Base Used:**
- [Monorepo build, validation, and release](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/monorepo-build-release.md)
- [Package delivery workflows](https://app.greptile.com/youversion/-/custom-context/knowledge-base/youversion/platform-sdk-react/-/docs/delivery-workflows.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Cursor Fix in Codex

Stack 2/3 of #382. Hooks-only changes: deep imports of YouVersionContext,
client-override fallback shape per hook, and query-key changes.
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