Skip to content

Fix reader app from crashing during improper setups#2937

Open
relyks wants to merge 1 commit intomasterfrom
fix-rendering-errors-for-faulty-setup
Open

Fix reader app from crashing during improper setups#2937
relyks wants to merge 1 commit intomasterfrom
fix-rendering-errors-for-faulty-setup

Conversation

@relyks
Copy link
Contributor

@relyks relyks commented Dec 19, 2025

This fixes a bug with rendering that can happen during local development and defends against faulty data.

Description

I don't always run the node server for server-side rendering during local development. Client-side rendering should still work even if the node server isn't used. When server-side rendering isn't properly setup to rebuild the cache to prepopulate the data, ReaderApp can crash. This can happen during local development. bookTitle might be null or undefined during the first render when the dependent React components mount. Sefaria.parseRef and/or Sefaria.index when using that bookTitle can return null or undefined for an uncached book.

Code Changes

Optional chaining and null checks were added to prevent components from crashing during rendering dependent on bookTitle.

…n during local development. When server-side rendering isn't properly setup to rebuild the cache and prepopulate data during local development
@relyks relyks self-assigned this Dec 19, 2025
@relyks relyks requested a review from yitzhakc December 19, 2025 01:08
settingsLanguage={this.state.settings.language == "hebrew"?"he":"en"}
toggleLanguage={this.toggleLanguage}
category={Sefaria.index(this.state.bookRef).primary_category}
category={Sefaria.index(this.state.bookRef)?.primary_category || "Other"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "Other" a fixed/ constant category? If so, it should be a const, and not a magic string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agreed.

Copy link
Contributor

@YishaiGlasner YishaiGlasner left a comment

Choose a reason for hiding this comment

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

If I understand correctly, we put here wrong data for solving dev problem (I don't understand the problem, I don't think i haver seen it). This can cause other bugs in the future.

Comment on lines +37 to +38
const index = this.props.bookTitle ? Sefaria.index(this.props.bookTitle) : null;
if (index) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that this should work and it seems to me cleaner

Suggested change
const index = this.props.bookTitle ? Sefaria.index(this.props.bookTitle) : null;
if (index) {
if (Sefaria.index(this.props?.bookTitle) {

@relyks
Copy link
Contributor Author

relyks commented Jan 6, 2026

If I understand correctly, we put here wrong data for solving dev problem (I don't understand the problem, I don't think i haver seen it). This can cause other bugs in the future.

How can this cause other bugs in the future? If the data is messed up in production or even local development, ReaderApp shouldn't crash, because a subcomponent can't render. There is something wrong with my local data and its indices, but this is a better solution anyway

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