Skip to content

Fix: null-guard API callbacks to prevent TypeError on network/auth failure#1003

Closed
mircealungu wants to merge 2 commits intomasterfrom
auto-fix/sentry-ZEEGUU-WEB-BX-BP-DN
Closed

Fix: null-guard API callbacks to prevent TypeError on network/auth failure#1003
mircealungu wants to merge 2 commits intomasterfrom
auto-fix/sentry-ZEEGUU-WEB-BX-BP-DN

Conversation

@mircealungu
Copy link
Copy Markdown
Member

Summary

Three production TypeErrors caused by _getJSON calling callback(null) on network/auth failure, while the callers read properties directly on the null value.

Sentry issue Occurrences Users Location
ZEEGUU-WEB-BX 80 62 App.jsgetUserPreferences callback
ZEEGUU-WEB-BP 75 53 ProgressContext.jsgetDailyStreak callback
ZEEGUU-WEB-DN 1 1 useSelectInterest.js — spread of null topics into newAllTopics

Root cause

classDef.js:104 already calls callback(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: add if (!preferences) return before reading preferences["audio_exercises"] (Fixes ZEEGUU-WEB-BX)
  • ProgressContext.js: add if (!data) return before reading data.daily_streak (Fixes ZEEGUU-WEB-BP)
  • useSelectInterest.js: guard setAvailableTopics/setSubscribedTopics against null so the spread in the dependent useEffect never sees null (Fixes ZEEGUU-WEB-DN)

Commit 2 — cleanup (Refactor: null-guard remaining callback and simplify isSubscribed (boy scout rule)):

  • Guard the getSubscribedSearchers callback in the same hook for consistency
  • Replace the verbose subscribedTopics.map().includes() ? true : false in isSubscribed with subscribedTopics.some()

To discuss this fix or request changes, find this session at:
https://claude.ai/code/session_01KZumy5REz1to8tCJEmuD5s

claude added 2 commits March 30, 2026 16:19
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
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 30, 2026

Deploy Preview for voluble-nougat-015dd1 ready!

Name Link
🔨 Latest commit b4f8004
🔍 Latest deploy log https://app.netlify.com/projects/voluble-nougat-015dd1/deploys/69caa2e8027c2b00082d5676
😎 Deploy Preview https://deploy-preview-1003--voluble-nougat-015dd1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member Author

Superseded by #1007 for the ProgressContext.js and useSelectInterest.js fixes. The App.js part is already covered by the promise migration in master. Closing.


Generated by Claude Code

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.

2 participants