Guard remaining unguarded Tauri calls for web deployments - #3190
Open
jefflitt1 wants to merge 2 commits into
Open
Guard remaining unguarded Tauri calls for web deployments#3190jefflitt1 wants to merge 2 commits into
jefflitt1 wants to merge 2 commits into
Conversation
Several call sites into @tauri-apps/api still assume a native Tauri runtime and throw when the desktop chat UI is served as a plain web page instead (no window.__TAURI_INTERNALS__): "Cannot read properties of undefined (reading 'transformCallback'/'invoke')". Most of the codebase already guards this correctly with isTauri() before calling listen()/invoke() (e.g. audioWorklet.ts); these were the remaining gaps, found by exercising a web-served build end-to-end: - useAgentsDataRefresh, usePreventSleep, useNestNotifications, HuddleContext, HuddleBar, HuddleIndicator, MobilePairingCard: guard listen() registration with isTauri(). - deep-link.ts: drainPendingCommunityDeepLinks() calls invoke() directly (not via the listen()-based subscription already guarded in this file) to read the Rust-side pending-deep-link queue, which only exists in the native shell — guard it the same way. - tauri.ts: isSharedIdentity() is called unconditionally at app boot, before any other Tauri-availability gate — guard it to resolve to `false` in a web runtime instead of throwing. - legacyCommunityStorage.ts: the legacy Sprout WebKit SQLite database read only exists in the native shell — skip it in a web runtime. All of these failures were already caught (logged as console warnings, not uncaught exceptions), so this doesn't change behavior for native Tauri users — it just removes console noise and dead invoke attempts when the same bundle is served as a website.
getDefaultRelayUrl/autoConnectDefaultRelayEnabled are called unconditionally by useCommunityInit's "no active community yet" branch on every boot, but that branch already wraps both calls in its own try/catch and falls back to needsSetup:true — so this is a console- noise reduction, not a behavior fix. setPreventSleepActive is different: usePreventSleep.ts calls it fire-and-forget (two call sites, both `void setPreventSleepActive(...)`) with no .catch of its own, so reaching invokeTauri here was a genuine unhandled promise rejection in a web (non-Tauri) runtime, not just noise.
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
@tauri-apps/apistill assume a native Tauri runtime and throw when the desktop chat UI is served as a plain web page instead (nowindow.__TAURI_INTERNALS__):"Cannot read properties of undefined (reading 'transformCallback'/'invoke')". Most of the codebase already guards this correctly withisTauri()before callinglisten()/invoke()(e.g.audioWorklet.ts); this fixes the remaining gaps, found by exercising a web-served build end-to-end.useAgentsDataRefresh,usePreventSleep,useNestNotifications,HuddleContext,HuddleBar,HuddleIndicator,MobilePairingCard: guardlisten()registration withisTauri().deep-link.ts:drainPendingCommunityDeepLinks()callsinvoke()directly (not via thelisten()-based subscription already guarded in this file) to read the Rust-side pending-deep-link queue, which only exists in the native shell — guard it the same way.tauri.ts:isSharedIdentity()is called unconditionally at app boot, before any other Tauri-availability gate — guard it to resolve tofalsein a web runtime instead of throwing.legacyCommunityStorage.ts: the legacy Sprout WebKit SQLite database read only exists in the native shell — skip it in a web runtime.All of these failures were already caught (logged as console warnings, not uncaught exceptions), so this doesn't change behavior for native Tauri users — it just removes console noise and dead
invokeattempts when the same bundle is served as a website.Independent of #3189, but both were found while exercising the same web-served build.
Test plan
pnpm build(tsc + vite build) passespnpm test— 3662/3662 passingpnpm exec biome checkon all 10 touched files — cleanRelated
Checked open PRs/issues for duplicates before submitting — no duplicate found. #3027 is open in an adjacent but different subsystem (relay-side SPA routing config, vs. this PR's desktop-client Tauri guards) for a similarly-motivated self-hosted deployment; not overlapping, noted for context.