OnMount fired twice for the same component
Hey hey, how it is going? I have this weird situation where I'm seeing a component being mounted twice. I was even able to see 2 DOM nodes mounted and I'd like to collect feedback if this has ever been a thing of it's just a me issue, doing non standard stuff. Code will follow:
21 Replies
This is the component being mounted twice
Modal root is a component that renders a
<dialog>
Can you show where you're using the component?
I'm seeing a component being mounted twice. I was even able to see 2 DOM nodes mountedThis suggests to me that there are two instances of the component rather than
onMount
running twice.Sure @jer3m01
@peerreynders I'm thinking the same thing!
I was able to identify where it does come from, the
<Show>
callback is runnig TWICE!
Oh yeah using a ternary condition to render when session.data is defined fixes my issuecan you wrap
console.log(" ======== Executing show callback with ", sessionData());
in an onMount
?Yessir, give me one sec I'll be sharing my console output for all the scenarios
On page load, when I navigate on my problematic page, this is what I have, the show callback is fired twice and it does generate 2 instances of the feedback modal
exact same thing, with a ternary fixes the issue
Now there's only one feedback modal
My
session.data
coming from Tanstack-Query, is a proxy object🤔
I KNOW RIGHT
can u try to make a minimal reproduction in the solid playground?
Yep I'm working on it, tbh no success atm
something fishy is going on 🙂
Could a reactive cycle cause this?
The modal seems to always exists once the session has been acquired.
The difference is that modal isn't open once it has been dismissed.
Ok gentlemen I found the culprit
The reconcile mechanism of tanstack query for Solid
GitHub
[solid-query] Using data in a show causes double-rendering after a ...
Describe the bug This might be a bug in Solid itself, but when passing a query's data to a <Show> with a function child, the child gets ran multiple times without being cleaned up properl...
Fix was implemented here https://github.com/TanStack/query/commit/a122e7cca52eed17d223e491a3c470ce72904d9b
GitHub
feat(solid-query): Rework internals of createBaseQuery (#7272) · Ta...
* feat(solid-query): Rework internals of createBaseQuery
This change aims to simplify and enhance the internals of
createBaseQuery
.
This change is a precursor to fix a couple of pressing issu...Thanks y'all! Chatting with y'all helped a lot lol. I just had to be vocal about it
Glad I can ship my feedback modal today 🔥
The modal seems to always exists once the session has been acquired.True and this was a side effect of my debugging journey. I'll be restoring the expected behaviour which is, if the modal is closed, it's not being rendered AT ALL
congrats on squashing that bug!
Thanks!