-
-
Notifications
You must be signed in to change notification settings - Fork 5
Ensure api-resources are always loaded #2161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis PR refactors the resource initialization logic in the project context by replacing a throttling-based mechanism with a queuing system that defers resource initialization until the API is available. The change introduces a queue for managing pending resource callbacks and generates unique identifiers for tracking resources. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
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 |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@frontend/viewer/src/project/project-context.svelte.ts`:
- Around line 119-122: The queued resource factories in setup()
(this.#queuedResources → factory(args.api)) get invoked twice because Svelte's
reactive resource source callback also calls factory(api); fix by ensuring only
one path runs: when you flush queued factories in setup(), mark those resources
as initialized (e.g., move their keys into a this.#initializedResources set or
delete them from this.#queuedResources) so the reactive resource source callback
can check that marker and early-return if the resource was already initialized;
alternatively, skip the flush and rely solely on the reactive path—apply the
change around the flush code that calls factory(args.api) and in the resource
source callback (the function that later calls factory(api)) to consult the same
marker before invoking factory.
- Around line 154-158: The queued factory promise can reject and currently
causes an unhandled rejection; update the callback stored in
this.#queuedResources[resourceId] (the function using
factory(api).then(res.mutate)) to handle errors by adding a .catch handler on
the Promise returned by factory(api) and surface the error (e.g., call a
resource error handler or log it) so failures don't become unhandled
rejections—ensure the callback uses factory(api).then(res.mutate).catch(err => {
/* handle or log err and notify resource */ }).
- Around line 120-121: The forEach callback currently uses the concise arrow
form which implicitly returns a value (Object.values(...).forEach(factory =>
factory(args.api));); update the callback to a block-bodied arrow that calls the
factory without returning anything—i.e., locate the Object.values<(api:
IMiniLcmJsInvokable) => void>(this.#queuedResources).forEach(...) line and
change the callback to use braces so it becomes factory => { factory(args.api);
} to satisfy the lint rule.
Due to refactoring, the entry row loading skeletons now tend to get destroyed faster. And strangely enough even though they're skeletons, they trigger loading parts-of-speech from the back end. They're the first component to load parts of speech, which means the loading effect (inside the runed resource) is scoped to their lifecycle (this is a bad pattern that I hadn't noticed before. I wasted lots of time looking for a clean way to redesign stuff, but failed to find anything really elegant). Because they started getting destroyed sooner, they were getting destroyed before the parts of speech were even loaded, which meant that the parts of speech never got loaded for any component that needed them 🙀.