Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix: stabilize local dev auth startup #3252

Closedhuxcrux(GitHub profile, opens in a new tab)wants to merge 12 commits intomain fromrefs/pull/3252/headopened View on GitHub

What Changed

  • Prevent Clerk-dependent desktop/web code from loading when Clerk local config is absent.
  • Register the desktop app scheme independently so local desktop startup no longer depends on Clerk side effects.
  • Route desktop custom-scheme requests through the app protocol using the Effect/Undici HTTP client.
  • Load the diff worker via the portable worker entry to avoid Vite worker default-export failures.
  • Route configured local-dev HTTP requests through the Vite origin while preserving direct WebSocket targets.
  • Harden pairing bootstrap by deduping same-token submits and tolerating already-authenticated stale token retries.

Why

Local development could fail when Clerk config was missing or when running the web dev flow through vp run dev. Clerk was being loaded too eagerly, desktop scheme registration depended on Clerk bridge setup, diff worker imports could fail under Vite, and pairing-token exchange could consume a one-time token before the browser session was observable on the correct origin.

This keeps local startup resilient without Clerk config, avoids CORS/cookie-origin issues by using the web/Vite origin for browser HTTP requests, and preserves direct loopback WebSockets where required.

UI Changes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk Desktop auth and renderer URL selection change in development, but production paths with a Clerk key stay on the custom protocol and bridge; mobile list scrolling behavior changes with the keyboard refactor.

Overview Makes local desktop dev work without Clerk by gating every Clerk touchpoint on whether a valid build-time publishable key resolves to a Frontend API hostname.

Desktop: New DesktopClerkConfig centralizes hostname parsing and isDesktopClerkBridgeEnabled(). The Clerk SDK bridge, preload exposeClerkBridge, and custom-scheme protocol registration are skipped when disabled; in that dev mode the main window loads the Vite dev server URL instead of t3code-dev://. makeDesktopClerkLayer can omit bridge acquire/release while still providing single-instance / second-window behavior.

Mobile: Thread chat drops KeyboardAwareLegendList / shared-value keyboard inset hooks in favor of KeyboardAvoidingLegendList, measured composer overlay height, and direct scrollToEnd after send.

Web: Adds a thin TimelineLegendList type wrapper so the timeline can pass contentInsetEndAdjustment without fighting LegendList typings.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 59f460b17118277762852842df15bd4bdcdad7e3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix local dev auth startup by conditionally initializing the Clerk bridge

  • Introduces DesktopClerkConfig.ts to centralize Clerk bridge enablement checks and hostname resolution from the publishable key.
  • The Electron custom protocol registration, preload bridge exposure, and SDK bridge acquisition are now all skipped when no Clerk publishable key is present (isDesktopClerkBridgeEnabled() === false).
  • Development builds without a publishable key load the renderer directly from the dev server URL instead of the custom t3code-dev protocol.
  • Refactors ThreadDetailScreen and ThreadFeed on mobile to use KeyboardAvoidingLegendList with manual composer layout tracking, removing Legend keyboard helpers.
Macroscope summarized 59f460b.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 4b99ca00-2b8d-42cd-a793-51b896f18c02

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low primary/auth.ts:317

      After exchangeBootstrapCredential resolves, submitServerAuthCredentialOnce immediately caches resolvedAuthenticatedGateState as authenticated without waiting for the server to confirm the session. Because resolveInitialServerAuthGateState returns that cached state, callers may observe authenticated before the session is actually valid. Consider awaiting waitForAuthenticatedSessionAfterBootstrap() after the exchange, as bootstrapServerAuth does.

      ✅ Resolved in 774e13effdeb6b010bf6383ba5d568fa500710ad

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR modifies runtime behavior in desktop auth startup and mobile keyboard/scroll handling. Unresolved review comments identify potential bugs in the scroll behavior changes that warrant human review before merging.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. juliusmarminge reviewed

      @@ -121,6 +162,19 @@
      121162 if (request.method !== "GET" && request.method !== "HEAD") {
      122163 init.body = request.body;
      123164 (init as RequestInit & { duplex: "half" }).duplex = "half";
      124165 }
      125- const response = await Electron.net.fetch(targetUrl.toString(), init);
      126- return withContentSecurityPolicy(response, contentSecurityPolicy);
      166+
      167+ const effect = Effect.gen(function* () {
      168+ const clientRequest = HttpClientRequest.fromWeb(new Request(targetUrl, init));
      169+ const clientResponse = yield* httpClient.execute(clientRequest);
      170+ return withContentSecurityPolicy(
      171+ new Response(
      172+ request.method === "HEAD" ? null : Stream.toReadableStream(clientResponse.stream),
      173+ {
      174+ status: clientResponse.status,
      175+ headers: clientResponse.headers,
      176+ },
      177+ ),
      178+ contentSecurityPolicy,
      179+ );
      180+ });

      why was this made? i ran into clerk bot protection when the fetch was made using undici earlier

      huxcrux(GitHub profile, opens in a new tab)commented

      This was an attempt to try keep the custom scheme for all app requests. However to avoid alot of the changes we could simply revert back to http://127.0.0.1 when clerk config is not present.

      I'll push a fix

    6. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 59f460b17118277762852842df15bd4bdcdad7e3. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -272,5 +273,4 @@
      272273 useEffect(() => {
      273274 setAnchorMessageId(null);
      274275 lastScrolledAnchorMessageIdRef.current = null;
      275- freeze.set(false);
      276- }, [freeze, selectedThreadKey]);
      276+ }, [selectedThreadKey]);

      Composer inset stale after changes

      Low Severity

      Replacing the keyboard inset hooks with composerOverlayHeight state means contentBottomInset can stay at an old measured value when estimatedOverlayHeight drops (for example after switching threads or when the working indicator clears) until onComposerLayout runs again, leaving excess bottom padding on the thread feed.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 59f460b17118277762852842df15bd4bdcdad7e3. Configure [here](https://www.cursor.com/dashboard/bugbot).
    7. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/59f460b17118277762852842df15bd4bdcdad7e3/apps/mobile/src/features/threads/ThreadDetailScreen.tsx#L289

      After sending a message from the focused composer, listRef.current?.scrollToEnd() runs immediately in the requestAnimationFrame callback, but at that point the keyboard is still dismissing and the KeyboardAvoidingLegendList has not finished adjusting its content insets. The scroll target is computed against the pre-keyboard-dismiss layout, so the newest message ends up scrolled underneath the closing keyboard instead of being fully visible. The previous useKeyboardScrollToEnd helper coordinated the scroll with the keyboard animation freeze so the list settled after the insets updated; removing it means freshly sent messages are not brought fully into view until the user manually scrolls.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/mobile/src/features/threads/ThreadDetailScreen.tsx around line 289:
      
      After sending a message from the focused composer, `listRef.current?.scrollToEnd()` runs immediately in the `requestAnimationFrame` callback, but at that point the keyboard is still dismissing and the `KeyboardAvoidingLegendList` has not finished adjusting its content insets. The scroll target is computed against the pre-keyboard-dismiss layout, so the newest message ends up scrolled underneath the closing keyboard instead of being fully visible. The previous `useKeyboardScrollToEnd` helper coordinated the scroll with the keyboard animation freeze so the list settled after the insets updated; removing it means freshly sent messages are not brought fully into view until the user manually scrolls.
    8. This has been fixed in main, closing the PR

Sign in to join this conversation.