Skip to content

Load page data once per control-plane navigation - #273

Merged
tnkuehne merged 1 commit into
mainfrom
remote-queries-outside-loads
Nov 22, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
remote-queries-outside-loads

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Workspace server loads awaited remote queries only to warm them and then discarded the results. SvelteKit serializes remote query results into the HTML of a full page render, but not into __data.json. On client-side navigation the server ran each query inside the data request, and the page component then requested the same query again, so every navigation waited for two sequential requests and repeated the database work.

The remote functions docs await queries in components. The components here already do that, which renders the data on the server for full page loads. Errors thrown by a query during rendering, such as the 404 from getAppDetails, set the response status and render +error.svelte.

Changes:

  • Remove the discarded prefetches from the home, apps, app, connections, services, API requests, settings administration, company sign-in, agents and members loads.
  • The app layout no longer depends on the full URL. Its per-section rerun only existed to repeat the removed prefetch; each section query authorizes its own request.

Loads that use a query result for a 404, a redirect or returned data (apps/new, services/[service]/*, services/requests/[requestId], settings/company-sign-in/setup, the selected app on services) are unchanged here.

Validation:

  • pnpm check equivalents: control-plane typecheck, oxfmt --check, oxlint --type-aware --deny-warnings.
  • Browser suite before the rebase onto Show settings sections as a collapsible sidebar group #271: 83 passed, 1 skipped, setup.spec.ts failed. It failed again when rerun alone (the first attempt hit EADDRINUSE from another local process on port 25430). It passed in the next full run with this change and on unchanged main.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking failures were found.

Summary

Removes discarded remote-query reads from server loads so client navigation does not fetch the same data twice.

  • Workspace pages load displayed data without a loader warm-up.

Diagram

sequenceDiagram
  participant Browser
  participant Load as Server load
  participant Component as Page component
  participant Query as Remote query
  Browser->>Load: Navigate
  Load-->>Browser: Route data
  Browser->>Component: Render page
  Component->>Query: Await displayed data
  Query-->>Component: Authorized result
Loading

Reviews (6) · Last reviewed commit: "Load page data once per control-plane na..." · Reviewed by Greptile

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs cd61a5e Nov 22 2026, 12:02 AM

Workspace server loads awaited remote queries only to warm them and then
discarded the results. SvelteKit serializes remote query results into the
HTML of a full page render, but not into __data.json. On client-side
navigation the server therefore ran each query inside the data request,
and the page component then requested the same query again. Every
navigation waited for two sequential Worker requests and repeated the
database work.

The components already await these queries, which renders them on the
server for full page loads and returns their 404 and other errors with
the matching status. Remove the discarded prefetches from the home, apps,
app, agents, connections, members, services, API requests and settings
loads.

The app layout no longer depends on the full URL to recheck access on each
section navigation. That recheck only came from the removed prefetch; the
section queries and the five-second app refresh authorize their own data.
@tnkuehne
tnkuehne force-pushed the remote-queries-outside-loads branch from 8dd5c50 to cd61a5e Compare November 22, 2026 00:01
@tnkuehne
tnkuehne merged commit 3833962 into main Nov 22, 2026
25 of 27 checks passed
@tnkuehne
tnkuehne deleted the remote-queries-outside-loads branch November 22, 2026 00:36
tnkuehne added a commit that referenced this pull request Nov 22, 2026
…275)

The workspace layout loaded the principal and organization list on every
navigation (`depends(url.href)`), and page guards read them through
`await parent()`. The [load
docs](https://svelte.dev/docs/kit/load#Implications-for-authentication)
note that layout loads do not run on every request and recommend
protecting routes in `handle` or in `+page.server.js`. The [auth
docs](https://svelte.dev/docs/kit/auth) and [remote functions
docs](https://svelte.dev/docs/kit/remote-functions#Implications-for-authentication)
add that remote functions must run their own checks, redirecting from
queries and forms and returning an error from commands.

Changes:
- **Request hook:** For workspace page and data requests,
`handleSession` now checks the organization selection and company SSO
after reading the session and before any load runs. Its redirects keep
the page as the return path. Form posts without JavaScript return to
their page without the action parameter. Remote requests are excluded
because remote functions authorize themselves.
- **Remote functions:** `remoteContext` (queries and forms) redirects a
caller without access. An ended session goes to sign-in, a required
company sign-in to that organization's sign-in, and an unavailable
organization selection to the organization chooser. The new
`commandContext` (settings commands and `manageWorkflow`) returns the
same denial as an error, because commands cannot redirect.
- **Page guards:** `settings/agents`, `welcome` and `apps/new` call
`pagePrincipal()` instead of `await parent()`. The legacy `/catalog`
redirect no longer waits for a parent load.
- **Workspace navigation:** `(workspace)/+layout.server.ts` is removed.
The layout awaits a new `getWorkspace` query for the principal and
organizations. `setMemberRole` refreshes it in the same response, and
other form submissions invalidate it by default. Analytics
identification moves from the root layout into `Workspace.svelte`.
- **Open tabs:** Tabs share one session. When a tab becomes visible,
`Workspace.svelte` refreshes `getWorkspace`. If another tab switched the
organization, the page reloads, which also resets unfinished forms so
they cannot submit to the new organization.

Behavior changes:
- A page whose data comes only from queries does not reach the hook on
client-side navigation. If the session ended or the organization
selection became unavailable, its query redirects to sign-in or the
chooser. A query request does not name its page, so that redirect has no
return path. Full page loads and data requests keep it.
- Another member's change to your role appears when your tab becomes
visible again, on reload or after a form submission, instead of on your
next click. Authorization is unaffected: remote functions and page loads
check the current role on every request.

Tests: the remote endpoint tests now expect a redirect to sign-in or the
organization chooser instead of a 401 or 403 error, and still check that
no data is returned. Session expiry and an unavailable selection during
client navigation expect the redirect without a return path in the
JavaScript variant. The role change test reloads the page. New coverage:
an open tab reloads with an empty form after another tab switches
organizations.

No visible UI change: the error page is unchanged from `main`.

Validation:
- `pnpm check` (typecheck, `oxfmt --check`, `oxlint --type-aware
--deny-warnings`)
- Browser suite (`test:e2e --grep-invert cli-login.spec.ts`) after
rebasing on #270: 86 passed, 1 skipped
- `handled-errors.integration.test.ts`: 14 passed

Stacked on #273.








<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=115298142&amp;sig=f9d9ac6ee3a218ef3e5737ee5d74742eca2af31f289d8101103cbc9db198089d"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F275&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no new
actionable issue was established.

<details open><summary><h3>Summary</h3></summary>

Workspace access checks move from the server layout into the request
hook. Queries and forms redirect callers who need to sign in or choose
an organization; commands return errors.

- Workspace pages check access before their loads run.
- Remote requests send denied members to the right sign-in or chooser
page.
- Workspace navigation refreshes when roles or organization selections
change.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Request] --> B[Read session]
  B --> C{Remote request?}
  C -- No, workspace page --> D[Check workspace access]
  D --> E[Run page loads]
  C -- Yes --> F{Remote function type}
  F -- Query or form --> G[Check access; redirect on denial]
  F -- Command --> H[Check access; return error on denial]
  E --> I[getWorkspace supplies sidebar data]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (5) · Last reviewed commit: ["Redirect signed-out remote
calls
instead..."](05a5fc6)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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