fix(ts-client): prevent Overview crash from single-resource cache seeding#3055
Conversation
…ding
updateSingleResource seeded the TanStack cache with { files: [...] }
when oldData was null (buffer replay race). This list-shaped fallback
broke single-resource queries like libraries.info where the response
is a plain object, causing TypeError on statistics.total_capacity.
Return undefined instead so the queryFn delivers the correct shape.
Batch seeding in updateBatchResources is preserved for file listings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe cache seeding behavior in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Summary
updateSingleResourceseeded the TanStack cache with{ files: [...], total_count, has_more }whenoldDatawas null (buffer replay race). This list-shaped fallback broke single-resource queries likelibraries.infowhere the response is a plainLibraryobject, causingTypeError: Cannot read properties of undefined (reading 'total_capacity')on the Overview page.undefinedinstead (TanStack no-op) so thequeryFndelivers the correct shape. Batch seeding inupdateBatchResourcesis preserved for file listings.Root Cause
The subscription manager pre-registers the listener before
transport.subscribe()(correct for capturing buffer replay). When the daemon has a recentResourceChangedforlibrary(fromrecalculate_statistics()), the buffer replay delivers it before thequeryFnresolves. WitholdDatanull, the fallback creates{ files: [Library] }which has nostatisticskey, crashing the Overview component.Why only
updateSingleResourceupdateBatchResourceskeeps its{ files: [...] }seeding becauseResourceChangedBatchevents are only emitted by the file indexing pipeline, where the list shape is correct. SingleResourceChangedevents affect all resource types (library, device, volume, location, tag), most of which don't use list-shaped responses.