Improve error surfacing when NEXT_PUBLIC_CORE_API_URL is misconfigured (#228)#313
Merged
Lakes41 merged 1 commit intoJul 24, 2026
Merged
Conversation
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.
Closes #228.
Addresses both failure modes for a misconfigured
NEXT_PUBLIC_CORE_API_URL: an invalid URL at startup, and a syntacticallyvalid but unreachable backend at runtime.
Investigation
Before writing any code, I traced through the existing config/error/offline
infrastructure to see what already existed vs. what was actually missing:
lib/config.tsalready throws aConfigErroratmodule-import time that names
NEXT_PUBLIC_CORE_API_URLexplicitly andexplains the expected format. No
error.tsx/global-error.tsxexists inapp/, so this surfaces as a raw build/startup failure rather than aformatted page — documented as expected behavior rather than "fixed",
since adding a custom error boundary for module-load-time errors is a
larger, riskier change than this issue calls for.
lib/api/backendStatus.tsalready had an
ensureOnline()health check and abackendOnlinereactiveflag, and
SyncStatusBannerwas already wired to read from it viauseSyncStatus(). ButensureOnline()was only ever called lazily,inside two API call sites in
lib/api/live.ts— meaning a broken backendURL produced no visible signal at all until a user happened to trigger
an action that hit the API. Additionally, the banner had no way to
distinguish "your browser is offline" from "the configured backend is
unreachable" — both showed the same generic offline copy.
Changes
components/backend-health-check.tsx(new)Invisible client component, same pattern as the existing
SwRegistrar,that calls
ensureOnline()once on mount. This is what makes theunreachable-backend case surface immediately on load instead of waiting
for a user action to fail.
app/layout.tsxMounts
<BackendHealthCheck />in the root layout, alongside the existing<SwRegistrar />/<SyncStatusBanner />.lib/offline/use-sync-status.tsAdded a new
isBackendReachablefield toSyncStatus, separate from theexisting combined
isOnlineflag, so the UI can tell the two failure modesapart.
components/ui/sync-status-banner.tsxAdded a new banner state: when the browser is online but
isBackendReachableis false, shows a distinct message — "Can't reachthe backend service... check that
NEXT_PUBLIC_CORE_API_URLis setcorrectly" — instead of the generic offline copy. Clears automatically
once
ensureOnline()succeeds again (reactive via the existingbackendOnline.subscribe()mechanism).docs/deployment.mdNew "Troubleshooting" section covering both failure modes: invalid URL
(build/startup failure, what the error looks like) and valid-but-unreachable
URL (what the banner looks like, how to diagnose it).
Acceptance criteria
and issue — pre-existing, verified and documented rather than
re-implemented.
silent failure — previously only reactive on user action; now also
proactive on load, with a message distinct from generic offline state.
docs/deployment.md's troubleshooting section.Notes for reviewers
lib/config.ts— its existingConfigErrormessaging wasalready good; verified this by reading it directly rather than assuming.
then corrected the docs) — it clears automatically when the backend
becomes reachable again.
error.tsxfor the invalid-URL case in afollow-up if maintainers want that too — kept out of this PR since it
wasn't explicitly required by the acceptance criteria and is a bigger
surface area to review.