Fix: null-guard API callbacks to prevent TypeError on network/auth failure#1003
Closed
mircealungu wants to merge 2 commits intomasterfrom
Closed
Fix: null-guard API callbacks to prevent TypeError on network/auth failure#1003mircealungu wants to merge 2 commits intomasterfrom
mircealungu wants to merge 2 commits intomasterfrom
Conversation
When _getJSON fails it calls callback(null). Three callers were reading properties on that null value, causing unhandled TypeErrors in production: - ZEEGUU-WEB-BX (80 events, 62 users): App.js getUserPreferences callback reading preferences["audio_exercises"] on null - ZEEGUU-WEB-BP (75 events, 53 users): ProgressContext.js getDailyStreak callback reading data.daily_streak on null - ZEEGUU-WEB-DN: useSelectInterest.js spreading null availableTopics / subscribedTopics into newAllTopics Fix: add early-return guard (if !data/preferences) in each callback, and prevent null from entering state for the topics arrays. Fixes ZEEGUU-WEB-BX, ZEEGUU-WEB-BP, ZEEGUU-WEB-DN https://claude.ai/code/session_01KZumy5REz1to8tCJEmuD5s
…y scout rule) - Guard getSubscribedSearchers callback against null for consistency with the other two topic callbacks fixed in the previous commit - Simplify isSubscribed: replace .map().includes() + ternary with .some() https://claude.ai/code/session_01KZumy5REz1to8tCJEmuD5s
✅ Deploy Preview for voluble-nougat-015dd1 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Member
Author
|
Superseded by #1007 for the Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three production TypeErrors caused by
_getJSONcallingcallback(null)on network/auth failure, while the callers read properties directly on the null value.App.js—getUserPreferencescallbackProgressContext.js—getDailyStreakcallbackuseSelectInterest.js— spread of null topics intonewAllTopicsRoot cause
classDef.js:104already callscallback(null)intentionally on failure ("so components don't hang on loading forever"). The three callers above didn't guard against that null before accessing properties.Commits
Commit 1 — core fix (
Fix: null-guard API callbacks to prevent TypeError on network failure):App.js: addif (!preferences) returnbefore readingpreferences["audio_exercises"](Fixes ZEEGUU-WEB-BX)ProgressContext.js: addif (!data) returnbefore readingdata.daily_streak(Fixes ZEEGUU-WEB-BP)useSelectInterest.js: guardsetAvailableTopics/setSubscribedTopicsagainst null so the spread in the dependentuseEffectnever sees null (Fixes ZEEGUU-WEB-DN)Commit 2 — cleanup (
Refactor: null-guard remaining callback and simplify isSubscribed (boy scout rule)):getSubscribedSearcherscallback in the same hook for consistencysubscribedTopics.map().includes() ? true : falseinisSubscribedwithsubscribedTopics.some()To discuss this fix or request changes, find this session at:
https://claude.ai/code/session_01KZumy5REz1to8tCJEmuD5s