Fix reader app from crashing during improper setups#2937
Fix reader app from crashing during improper setups#2937
Conversation
…n during local development. When server-side rendering isn't properly setup to rebuild the cache and prepopulate data during local development
| 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"} |
There was a problem hiding this comment.
Is "Other" a fixed/ constant category? If so, it should be a const, and not a magic string.
YishaiGlasner
left a comment
There was a problem hiding this comment.
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.
| const index = this.props.bookTitle ? Sefaria.index(this.props.bookTitle) : null; | ||
| if (index) { |
There was a problem hiding this comment.
it seems that this should work and it seems to me cleaner
| const index = this.props.bookTitle ? Sefaria.index(this.props.bookTitle) : null; | |
| if (index) { | |
| if (Sefaria.index(this.props?.bookTitle) { |
How can this cause other bugs in the future? If the data is messed up in production or even local development, |
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.
bookTitlemight be null or undefined during the first render when the dependent React components mount.Sefaria.parseRefand/orSefaria.indexwhen using thatbookTitlecan 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.