Skip to content

Conversation

@bmanquen
Copy link
Collaborator

@bmanquen bmanquen commented Feb 3, 2026

  • Conditionally render the user menu in the bible reader toobar so that the reader does not crash if user has auth disabled.
  • Conditionally call the useAuth() hook only if the user has auth enabled.
  • Write test to ensure that the bible reader can be used with auth disabled from the YouVersionProvider.

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: d33022b

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
@youversion/platform-core Patch
nextjs 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

@bmanquen bmanquen force-pushed the bm/YPE-1133-fix-bible-reader branch from fafc1e1 to 01b8d4d Compare February 3, 2026 12:29
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 3, 2026

Greptile Overview

Greptile Summary

Fixed crash when auth is disabled by conditionally rendering the UserMenu component based on an authEnabled flag in the YouVersionContext.

Key Changes

  • Added authEnabled boolean to YouVersionContext that tracks whether auth is enabled
  • Extract UserMenu into separate component in bible-reader.tsx
  • Conditionally render UserMenu only when authEnabled is true, preventing useYVAuth hook from being called without auth context
  • Updated Storybook preview to conditionally set up YouVersionProvider with/without auth based on story parameters
  • Added comprehensive test story "WithoutAuth" to verify BibleReader works correctly when auth is disabled

Technical Approach

The fix correctly leverages React's conditional rendering to prevent the useYVAuth hook from being called when auth is disabled. Since useYVAuth calls useYouVersionAuthContext() which throws an error when auth context is unavailable, the component must not render at all when auth is disabled.

Confidence Score: 4/5

  • Safe to merge with one minor style improvement suggested
  • The implementation correctly fixes the auth crash issue using conditional rendering. The test coverage is comprehensive. Minor style improvement suggested for using early returns instead of if-else blocks.
  • No critical issues, but consider the style improvement in packages/ui/.storybook/preview.tsx

Important Files Changed

Filename Overview
packages/hooks/src/context/YouVersionProvider.tsx Sets authEnabled flag based on includeAuth prop in both auth branches
packages/ui/.storybook/preview.tsx Conditionally sets up YouVersionProvider with or without auth based on story parameters
packages/ui/src/components/bible-reader.tsx Extracted UserMenu component and conditionally renders it based on authEnabled context flag

Sequence Diagram

sequenceDiagram
    participant App
    participant Provider as YouVersionProvider
    participant Context as YouVersionContext
    participant Reader as BibleReader
    participant Toolbar
    participant Menu as UserMenu

    Note over App,Menu: Auth Disabled Flow
    App->>Provider: includeAuth: false
    Provider->>Context: authEnabled: false
    Reader->>Toolbar: render
    Toolbar->>Context: check authEnabled
    Context-->>Toolbar: false
    Toolbar->>Toolbar: skip UserMenu
    Note over Menu: UserMenu not rendered<br/>useYVAuth not called

    Note over App,Menu: Auth Enabled Flow
    App->>Provider: includeAuth: true
    Provider->>Context: authEnabled: true
    Reader->>Toolbar: render
    Toolbar->>Context: check authEnabled
    Context-->>Toolbar: true
    Toolbar->>Menu: render UserMenu
    Menu-->>Toolbar: display auth UI
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +52 to +66
if (includeAuth) {
return (
<StorybookEnvCheck requiredEnvVars={requiredEnvVars}>
<YouVersionProvider
appKey={import.meta.env.STORYBOOK_YOUVERSION_APP_KEY || ''}
authRedirectUrl={import.meta.env.STORYBOOK_AUTH_REDIRECT_URL || ''}
apiHost={import.meta.env.STORYBOOK_YOUVERSION_API_HOST}
includeAuth={true}
theme={getTheme(context.globals.theme)}
>
<Story />
</YouVersionProvider>
</StorybookEnvCheck>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use early return instead of if-else to reduce nesting. Invert the condition to check !includeAuth first and return early with the simpler case (without auth), then return the auth case at the end.

Context Used: Rule from dashboard - Avoid unnecessary negations and else blocks to reduce nesting and improve code readability. Use earl... (source)

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!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/.storybook/preview.tsx
Line: 52:66

Comment:
Use early return instead of if-else to reduce nesting. Invert the condition to check `!includeAuth` first and return early with the simpler case (without auth), then return the auth case at the end.

**Context Used:** Rule from `dashboard` - Avoid unnecessary negations and else blocks to reduce nesting and improve code readability. Use earl... ([source](https://app.greptile.com/review/custom-context?memory=b2f865f5-91b5-4c90-89be-43dc9c513644))

<sub>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!</sub>

How can I resolve this? If you propose a fix, please make it concise.

- Conditionally render the user menu in the bible reader toobar
so that the reader does not crash if user has auth disabled.
- Conditionally call the useAuth() hook only if the user has
auth enabled.
- Write test to ensure that the bible reader can be used with
auth disabled from the YouVersionProvider.
@bmanquen bmanquen force-pushed the bm/YPE-1133-fix-bible-reader branch from 01b8d4d to d33022b Compare February 3, 2026 12:32
Copy link
Collaborator

@cameronapak cameronapak left a comment

Choose a reason for hiding this comment

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

Good work! One suggestion added

@@ -245,42 +289,7 @@ function Toolbar({ border = 'top' }: { border?: 'top' | 'bottom' }) {
)}
>
<div className="yv:grid yv:w-full yv:grid-cols-7 yv:items-center yv:max-w-lg yv:gap-0.5">
Copy link
Collaborator

Choose a reason for hiding this comment

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

{authEnabled && <UserMenu />}

When authEnabled=false, this renders nothing but the grid still has 7 columns (grid-cols-7). This may cause layout shift or misalignment.

Suggestion: Can you adjust grid columns dynamically or render a placeholder <div />?

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.

3 participants