-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(svelte-query): fix error when creating query outside of component #9222
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
fix(svelte-query): fix error when creating query outside of component #9222
Conversation
… initialization Add $effect.root to allow creating queries in event handlers. Previously creating a query outside of component initialization would throw an effect_orphan error
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 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 |
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.
Hi @arnolicious , could you also create a repro or a test for your bug?
View your CI Pipeline Execution ↗ for commit 84fe536
☁️ Nx Cloud last updated this comment at |
I wasn't sure how best to do this, because in the tests this change basically only results in not needing the <script>
const onCreateQuery = () => {
createQuery({...})
}
</script>
<button onclick={onCreateQuery} /> Let me know if you have other ideas for the tests |
What's the purpose of calling createQuery in an event like that? It seems like there might be a better way to achieve what you're after, but I might be missing something! |
I encountered this when working on a decently complex use case, but very roughly:
The end result is basically:
And the child queries being created on demand, imperatively. Considering the small fix, this seemed like the easiest solution |
It sounds like this might be more easily and more "correctly" solved with child components - are you able to spin up a repro? |
I won't really be able to create a reproduction for this use case, since the corresponding api is the central reason why this is needed. Child components cannot be used, because to work with the data and display it, I actually flatten all items into a simple array. If this doesn't get merged, I would be fine with it, as I have been running this patch since discovering the issue. |
Description
This fixes an
effect_orphan
error that occurs, whencreateQuery
gets called in an event listener, or simply outside of component initialization.I simply added
$effect.root
around the$effects
increateBaseQuery.svelte.ts
which fixed the error on my end while seemingly not breaking anything.