Skip to content

[codex] Render cached workspaces before sync#4820

Merged
Kitenite merged 1 commit into
mainfrom
electric-local-first
May 21, 2026
Merged

[codex] Render cached workspaces before sync#4820
Kitenite merged 1 commit into
mainfrom
electric-local-first

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented May 21, 2026

Summary

  • Stop gating workspace host targeting and v2 workspace layout rendering on Electric $synced once a cached workspace row exists.
  • Let remote host status render from cached workspace data even when the host collection has not reached isReady.
  • Remove the unused sidebar isSynced field from the rendered workspace model so components cannot accidentally block on it.

Root Cause

TanStack DB live queries can return persisted rows before the Electric collection reports readiness or $synced === true. The v2 workspace route and host-target hook were still treating those sync states as UI readiness, so an Electric outage or delayed shape could blank an otherwise cached workspace.

Impact

Cached workspace rows now remain usable while Electric catches up. isReady is only used to distinguish loading from not-found when no row exists, and $synced remains only as internal bookkeeping for clearing pending insert state.

Validation

  • bun run lint:fix
  • bun run lint
  • bun run --cwd apps/desktop typecheck

Open in Stage

Summary by cubic

Render cached workspace rows before Electric sync so the v2 workspace layout and remote host status don’t blank while shapes catch up. Improves resiliency during Electric outages or delays.

  • Bug Fixes
    • Stop gating workspace layout and host targeting on $synced/isReady when a cached workspace row exists.
    • Render remote host status from cached data; drop readiness check in useRemoteHostStatus.
    • Remove isSynced from the sidebar workspace model and related gating in V2WorkspaceLayout.

Written for commit fa650ea. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced workspace responsiveness through optimized state detection
    • Dashboard workspace status (loading, incompatible states) now displays more consistently without unnecessary delays
    • Workspace functionality determined faster based on query readiness
    • Sidebar updates respond more dynamically to workspace availability

Review Change Stack

@capy-ai
Copy link
Copy Markdown

capy-ai Bot commented May 21, 2026

Capy auto-review is paused for this organization because the monthly auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews.

@stage-review
Copy link
Copy Markdown

stage-review Bot commented May 21, 2026

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Remove unused isSynced from sidebar types
2 Allow workspace host targeting without sync gating
3 Enable remote host status rendering from cache
4 Render v2 workspace layout from cached data
Open in Stage

Chapters generated by Stage for commit fa650ea on May 21, 2026 9:50pm UTC.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ccda911d-e32d-430b-b344-8cb061cb2bb8

📥 Commits

Reviewing files that changed from the base of the PR and between b59bc01 and fa650ea.

📒 Files selected for processing (5)
  • apps/desktop/src/renderer/hooks/host-service/useWorkspaceHostUrl/useWorkspaceHostUrl.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarData/useDashboardSidebarData.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/types.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/layout.tsx

📝 Walkthrough

Walkthrough

The PR removes isSynced flag and isReady-based loading gates across workspace host determination and dashboard sidebar flows. Host URL readiness, remote host status checks, and dashboard layout orchestration now rely on query data presence instead of explicit sync state checks.

Changes

Workspace Host Readiness Refactor

Layer / File(s) Summary
Dashboard Sidebar Type Contract Update
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/types.ts
DashboardSidebarWorkspace removes isSynced: boolean and adds createdAt: Date, updatedAt: Date, and taskId: string | null fields.
Host URL Determination Hook
apps/desktop/src/renderer/hooks/host-service/useWorkspaceHostUrl/useWorkspaceHostUrl.ts
useWorkspaceHostUrl stops selecting and checking the isSynced field; state transitions between loading, not-found, and ready are determined by isReady and the presence/absence of the matching workspace row.
Remote Host Status Hook
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts
useRemoteHostStatus removes isReady from the useLiveQuery destructuring and eliminates the conditional loading gate, leaving only workspace/machine and info query checks to determine loading behavior.
Dashboard Layout Integration
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/layout.tsx
Layout removes the canUseWorkspace condition, updates ensureWorkspaceInSidebar to depend only on workspace existence, and removes the early-return block that previously hid content when workspace was not ready, allowing host status UI and workspace provider to render under broader conditions.
Sidebar Data Construction
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarData/useDashboardSidebarData.ts
sidebarWorkspace object construction removes isSynced assignment and includes new metadata fields (createdAt, updatedAt, taskId) aligned with the updated type contract.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • superset-sh/superset#4746: Reverses the same useWorkspaceHostUrl workspace readiness logic by removing the $synced (isSynced) gating that #4746 introduced and similarly shifts dashboard sidebar types away from that check.
  • superset-sh/superset#4740: Both PRs modify the dashboard sidebar workspace model to stop using isSynced and drive "pending/creating" state from transaction and pending states instead.
  • superset-sh/superset#4672: Modifies the same useRemoteHostStatus hook and v2 workspace layout.tsx flow around remote host state handling; retrieved PR adds an "offline" status gated by isOnline.

Poem

🐰 No more synced delays, the query speaks true,
Data presence decides what the workspace can do,
Readiness flows faster, no gates in the way,
Host status shines bright on the dashboard today! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch electric-local-first

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR removes Electric sync-state gates ($synced, isReady) from the v2 workspace rendering path so that TanStack DB persisted cache rows are used for UI immediately, regardless of whether Electric has caught up. The changes are focused and internally consistent.

  • layout.tsx drops the canUseWorkspace guard, allowing the workspace to render and ensureWorkspaceInSidebar to fire as soon as a cached row exists, regardless of $synced state.
  • useRemoteHostStatus removes the isReady && !hostRow loading gate; for remote workspaces it now falls through to \"ready\" immediately while infoQuery (the actual version-compatibility check) is still in-flight, which can produce a brief flash of workspace content before an incompatible-host screen appears.
  • isSynced is removed from DashboardSidebarWorkspace type and its mapping, eliminating the accidental coupling point for downstream components.

Confidence Score: 4/5

Safe to merge; the only observable regression is a brief flash of workspace content for incompatible remote hosts before the incompatibility screen takes over.

All changes are intentional and the logic holds for the common path. The one edge to watch is useRemoteHostStatus now returning "ready" immediately for remote workspaces while the host version check is still in-flight — users on incompatible hosts will momentarily see the workspace UI before being bounced to the incompatible-host screen. The isSynced removal is clean and the type/mapping changes are consistent throughout.

useRemoteHostStatus.ts — the immediate "ready" return before infoQuery settles is the only behavior worth validating against incompatible-host scenarios.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/layout.tsx Removes canUseWorkspace guard; workspace now renders from cache without waiting for $synced, and ensureWorkspaceInSidebar fires as soon as workspace row is non-null.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts Drops isReady from the hosts live-query; for remote workspaces the function now falls through to "ready" immediately, before infoQuery resolves, which can briefly show workspace content before an incompatible-host screen appears.
apps/desktop/src/renderer/hooks/host-service/useWorkspaceHostUrl/useWorkspaceHostUrl.ts Removes isSynced selection and the resulting loading gate; the existing isReady && !match guard still covers the true empty-cache case.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarData/useDashboardSidebarData.ts Removes isSynced from the mapped workspace object, consistent with type change; no logic altered.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/types.ts Removes isSynced from DashboardSidebarWorkspace interface, aligning the type with the mapping change.

Sequence Diagram

sequenceDiagram
    participant Cache as TanStack DB Cache
    participant Layout as V2WorkspaceLayout
    participant RHS as useRemoteHostStatus
    participant IQ as infoQuery (React Query)
    participant Electric as Electric Sync

    Note over Cache,Electric: PR change: render from cache without waiting for Electric $synced

    Cache->>Layout: "workspace row (cached, $synced=false)"
    Layout->>RHS: useRemoteHostStatus(workspace)
    RHS-->>Layout: "status=ready (immediate, no isReady gate)"
    Layout->>Layout: render WorkspaceProvider + Outlet

    IQ-->>RHS: version check resolves
    alt host incompatible
        RHS-->>Layout: "status=incompatible"
        Layout->>Layout: render WorkspaceHostIncompatibleState
    end

    Electric-->>Cache: "$synced=true"
    Cache->>Layout: workspace row updated
    Layout->>Layout: clearWorkspaceTransaction (insert done)
Loading

Comments Outside Diff (1)

  1. apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts, line 68-83 (link)

    P2 Workspace may briefly flash before incompatibility is shown

    After removing the isReady && !hostRow guard, the function falls straight through to { status: "ready" } for any remote workspace while infoQuery is still in-flight. layout.tsx renders <WorkspaceProvider> / <Outlet> for any "ready" status, so if infoQuery later resolves to an incompatible version, the user sees a flash of live workspace content before the WorkspaceHostIncompatibleState replaces it. Previously, the isReady gate provided at least a brief loading state that masked this race. The impact is narrow (only incompatible hosts) and may be an acceptable UX trade-off, but it is worth noting since hostStatus.status === "loading" in layout.tsx no longer fires for remote workspaces at all.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts
    Line: 68-83
    
    Comment:
    **Workspace may briefly flash before incompatibility is shown**
    
    After removing the `isReady && !hostRow` guard, the function falls straight through to `{ status: "ready" }` for any remote workspace while `infoQuery` is still in-flight. `layout.tsx` renders `<WorkspaceProvider>` / `<Outlet>` for any "ready" status, so if `infoQuery` later resolves to an incompatible version, the user sees a flash of live workspace content before the `WorkspaceHostIncompatibleState` replaces it. Previously, the `isReady` gate provided at least a brief loading state that masked this race. The impact is narrow (only incompatible hosts) and may be an acceptable UX trade-off, but it is worth noting since `hostStatus.status === "loading"` in `layout.tsx` no longer fires for remote workspaces at all.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/hooks/useRemoteHostStatus/useRemoteHostStatus.ts:68-83
**Workspace may briefly flash before incompatibility is shown**

After removing the `isReady && !hostRow` guard, the function falls straight through to `{ status: "ready" }` for any remote workspace while `infoQuery` is still in-flight. `layout.tsx` renders `<WorkspaceProvider>` / `<Outlet>` for any "ready" status, so if `infoQuery` later resolves to an incompatible version, the user sees a flash of live workspace content before the `WorkspaceHostIncompatibleState` replaces it. Previously, the `isReady` gate provided at least a brief loading state that masked this race. The impact is narrow (only incompatible hosts) and may be an acceptable UX trade-off, but it is worth noting since `hostStatus.status === "loading"` in `layout.tsx` no longer fires for remote workspaces at all.

Reviews (1): Last reviewed commit: "Render cached workspaces before sync" | Re-trigger Greptile

@Kitenite Kitenite merged commit 6085d7e into main May 21, 2026
9 of 10 checks passed
@Kitenite Kitenite deleted the electric-local-first branch May 21, 2026 21:53
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

MocA-Love added a commit to MocA-Love/superset that referenced this pull request May 25, 2026
MocA-Love pushed a commit to MocA-Love/superset that referenced this pull request May 25, 2026
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.

1 participant