Title: fix(files): read the Files prefetch from the data layer and bound invitation previews by waleedlatif1 · Pull Request #6415 · simstudioai/sim · GitHub
Open Graph Title: fix(files): read the Files prefetch from the data layer and bound invitation previews by waleedlatif1 · Pull Request #6415 · simstudioai/sim
X Title: fix(files): read the Files prefetch from the data layer and bound invitation previews by waleedlatif1 · Pull Request #6415 · simstudioai/sim
Description: Summary
Two unrelated load-time fixes, 8 files.
Files page (/workspace/[id]/files). On a hard refresh the folders painted first and the files a beat later. Both are prefetched and hydrated together, so the files entry was not reaching the client. Each read went to its own route over an internal HTTP request — prefetchQuery swallows a rejection and shouldDehydrateQuery drops the errored entry, so a failure there silently ships a page with that list missing, and the files read is the heavier of the two (it joins share rows on top of the file rows). Those two reads now call the data layer, which also removes a server→server request and its duplicate auth from the render path.
Root cause is not confirmed. Staging logs show zero errors from WorkspaceFilesAPI over three days, so this removes the failure mode without proving it was the one firing. What the logs do show on the reported workspace is duplicate requests 13–42ms apart, consistent with the hydrated entry not being used — but those logs don't distinguish server-originated from browser-originated requests. The request dropped from the render path and the shape fix below stand on their own.
Shape fix (real bug). listWorkspaceFilesWithShares is shared by the route and the prefetch and shapes its result through the route contract's response schema — the technique prefetchWorkspaceSidebar already documents. listWorkspaceFiles returns contentUpdatedAt, which workspaceFileRecordSchema neither declares nor passes through, so the prefetch was caching a field a client fetch never has and that vanished on the next refetch.
Authorization. The reads carry none of their own now that they bypass the route, so the prefetch proves the viewer first. It reuses the layout's cache()d getWorkspaceHostContextForViewer rather than re-deriving the permission, so the gate costs no additional queries. No access → nothing cached → the client fetch reaches the route for the real 403.
Invitations. GET /api/invitations computed join previews in a serial loop, and each preview issues up to three queries of its own — all on the critical path of the workspace switcher opening. Bounded with mapWithConcurrency. Same fetch, same trigger, same payload; the mapper was already total, which is what that helper requires.
Deliberately not included: no conversion of the home/tables/knowledge/chrome prefetches, no lib/table refactor, no invitation prefetching. Those were explored and dropped — the tables conversion is blocked by check:tool-registry-boundary (lib/table/service transitively imports the executor), and prefetching invitations would have put these queries back on every workspace page render.
Type of Change
Bug fix
Testing
Tested manually.
Three new tests, each verified to fail without its fix: the concurrency bound (set limit to 1 → red), the contract strip (remove the parse → red), and the prefetch auth gate (remove the guard → red).
Deleted a test I had written that couldn't fail — it pinned prefetchQuery's swallow behaviour rather than anything in this diff, and passed against origin/staging unchanged.
Updated the existing prefetch.test.ts rather than letting it rot, including its graceful-failure case, which was asserting against a fetcher the Files prefetch no longer uses and would have passed vacuously.
bun run check:audits, type-check, lint all pass. Pre-existing and unrelated: check:realtime-prune, check:native-typecheck and check:desktop-bridge fail in a worktree with no local node_modules — verified identical on clean origin/staging.
Not browser-verified. Worth one hard refresh of /files with the network tab open before merge: if /api/workspaces/
Open Graph Description: Summary Two unrelated load-time fixes, 8 files. Files page (/workspace/[id]/files). On a hard refresh the folders painted first and the files a beat later. Both are prefetched and hydrated together...
X Description: Summary Two unrelated load-time fixes, 8 files. Files page (/workspace/[id]/files). On a hard refresh the folders painted first and the files a beat later. Both are prefetched and hydrated together...
Opengraph URL: https://github.com/simstudioai/sim/pull/6415
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e8802300-45af-e67d-fff0-cf5c4fb68f8e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A924:11E6AB:250522:34C10A:6AFB5284 |
| html-safe-nonce | 551ba5a8b795c32dd632c0b8a70164f1d7f302723dd487b293a691a83e1e497c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTI0OjExRTZBQjoyNTA1MjI6MzRDMTBBOjZBRkI1Mjg0IiwidmlzaXRvcl9pZCI6IjMwODA4NDA5NTQ0NDE4NDc0MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 04cc5e1a7f386ee71cd47a23ea9c0b405d073bcffe95801a60e2caffc29eaf33 |
| hovercard-subject-tag | pull_request:4235491202 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6415/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Two unrelated load-time fixes, 8 files. Files page (/workspace/[id]/files). On a hard refresh the folders painted first and the files a beat later. Both are prefetched and hydrated together... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width