any way to update a signal without it causing a reactive update?
i tried untrack but it didn't work
12 Replies
https://xyproblem.info/
What actual problem would that solve?
I have a signal on a previous page that has a list of completed entries and then on the entry page which is on a separate route when I complete one. I want to update the original signal so that when the user hits the back button that entry is completed. however, the entries are a resource that can either be in a loading State, a data state, or an error state. and currently if I update an entry to be completed on the entry page by modifying the original signal list then the entire page re-renders but I do not want this because I want it to maintain its current state
however, when you go back because the route re-renders as long as we update the original signal we don't have to refetch the data and also the route renders with the updated entry
My solution would be to use a regular variable instead, and have the other page actively pull from there when rendering. If you also want to sometimes have reactive updates, then you can write an abstraction that allows controlling whether only the variable gets modified, or if the signal gets updated
It's certainly not possible to prevent an update when calling the setter (untrack works for the read side, so it doesn't subscribe. But you can't set a setter and expect listeners to not update, excluding batch rules which just defer of course )
The issue with that approach is that if a user is directly linked to the entry page, it should fetch the listings such that when the user goes back they don't have to do another fetch. in addition, I cannot use a regular variable on this page because I want to have a reactive response depending on whether or not the data being fetched is currently loading or potentially is in an error state
anyways, I figured out a Band-Aid solution so it's okay you don't have to waste any more time thinking about this, I was just wondering if there was a trivial solution like an untrack for writing
You probably want an abstraction then, that allows you to control that
Just some thoughts:
the entries are a resourceAnd as such represent "server state"
then the entire page re-rendersThis happens because you have the entire list in a signal. For the list to change the entire list has to change, consequently the entire page updates. What you want is fine-grained reactivity with a store. There you can use
reconcile
to merge server state with local state. At that point adding a new entry doesn't update the entire page (like keeping the whole list of entries in a signal does).reconcile - SolidDocs
Documentation for SolidJS, the signals-powered UI framework
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
oh, interesting approach. this works? there's nothing that can go wrong?
not really.
if your use case need an unreactive signal update, that is one way to do that.
it will just shift the control to you, when you might want to trigger the change
cool thanks!
https://playground.solidjs.com/anonymous/f6a46d01-c21d-4fd1-9fa7-42f67e60af0b
this fixes the type issue I think.
one more thing to keep in mind is that when you use the non silent setter it will always trigger.
not a big deal, but it will allow you to trigger with the value that was set last silently.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
oh great thanks again!