fix(desktop): use searchParams not string concat for terminal WS URL#4159
Conversation
#4149 appended `?themeType=...` to a URL that already had `?token=<jwt>`, producing `?token=jwt?themeType=light`. Hono's `c.req.query("token")` then read the JWT with `?themeType=light` appended, failing `validateToken()` -> 401 on every WS upgrade. As a bonus, `c.req.query("themeType")` returned null, so the themeType forwarding this PR was trying to enable was dead code. Build the URL via URL.searchParams so the existing token param is preserved and themeType lands as a real query parameter.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesWebSocket URL Construction
Estimated Code Review Effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a URL construction bug introduced in #4149 where appending
Confidence Score: 5/5Safe to merge — the change is a minimal, targeted fix to a broken URL construction that was already causing 100% terminal connection failures. The three-line change is correct: useWorkspaceWsUrl already returns a valid absolute URL string (it uses URL internally), so constructing new URL(baseWebsocketUrl) is safe. searchParams.set handles encoding automatically and places themeType as a proper ampersand-separated parameter rather than a second question mark. The intentional ref-based design that keeps themeType out of the reconnect effect dependencies is preserved unchanged. No files require special attention — the change is confined to three lines within TerminalPane.tsx and has no ripple effects on other modules.
|
| Filename | Overview |
|---|---|
| apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx | Replaces string concatenation for WebSocket URL construction with URL.searchParams.set(), correctly placing themeType as a proper query parameter without breaking the existing auth parameter. |
Sequence Diagram
sequenceDiagram
participant C as TerminalPane (renderer)
participant H as useWorkspaceWsUrl
participant S as host-service (server)
Note over C,H: Before fix - broken URL construction
H->>C: ws://host/terminal/id with auth param already set
C->>C: string concat appends second question mark to URL
C->>S: WS upgrade with malformed double-question-mark URL
S->>S: auth param value gets corrupted - validation fails
S->>S: themeType query returns null
S-->>C: 401 Unauthorized - terminal unreachable
Note over C,H: After fix - correct URL construction
H->>C: ws://host/terminal/id with auth param already set
C->>C: new URL(base).searchParams.set adds themeType properly
C->>S: WS upgrade with both params as separate query entries
S->>S: auth param parsed correctly
S->>S: themeType parsed correctly
S-->>C: 101 Switching Protocols - terminal connected
Reviews (1): Last reviewed commit: "fix(desktop): use searchParams not strin..." | Re-trigger Greptile
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
#4149 appended
?themeType=...to a URL that already had?token=<jwt>, producing?token=jwt?themeType=light. Two failures:c.req.query(\"token\")(packages/host-service/src/app.ts:143) reads everything after the first?token=up to the next&— so the parsed token iseyJ...?themeType=light, which failsvalidateToken(). Every WS upgrade gets 401. This is the "every terminal unreachable" symptom that surfaced on the desktop-v1.8.5 draft.c.req.query(\"themeType\")returnsnullbecause there's no real&themeType=...in the URL — it's part of the token value. So the host-side respawn fallback that fix(terminal): respawn lost sessions on attach; route WS errors to log #4149 was trying to make theme-aware silently uses defaults.Fix
Build the URL via
URL.searchParamsso the existingtokenparam is preserved andthemeTypelands as a real query parameter:Preserves the PR's design intent (`baseWebsocketUrl` stays stable so theme toggles don't trigger reconnects via the effect deps; `websocketUrl` is read off the ref inside the effect).
Test plan
token=\"eyJ...?themeType=light\", themeType=nulldesktop-v1.8.5after merge, confirm the new draft build shows working terminalsSummary by cubic
Fixes terminal WebSocket URL building in Desktop by using URL.searchParams instead of string concatenation. Preserves the existing
tokenand correctly forwardsthemeType, restoring auth and theme-aware respawn.URL.searchParamsto appendthemeTypewithout corruptingtoken.themeTypequery param.Written for commit 8b3502b. Summary will update on new commits.
Summary by CodeRabbit