-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
How "written in stone" is the rule about not changing state in $derived? #14793
Comments
Couldn't you use an |
It is using |
Ah, I see, then #14784 would probably be the best solution, if it's merged. |
Interesting. So the new |
It's "written in stone" insofar that the current behavior is there to ensure consistency of the reactive graph. Else mutations could produce subtle and indirect bugs which you would spend hours debugging. #14784 would certainly help with this, therefore closing. |
Yes, thank you for the explanation. I'm impatiently waiting for that PR to go live. 😄 |
Describe the problem
My component
@wjfe/dataview
uses a$derived
to calculate the necessary information to lay out the component's data columns. This is great. Actually, the entire component is driven by just this one computation.However, at work there is this need: In data drilling scenarios where "row expansion" shows another table that describes in more detail the expanded row's data (see this page for a live data-drilling example), users want that certain columns of the "child" table be visually synchronized in position and width with the equivalent parent table's column.
To achieve this, I have been thinking about this long and hard and I finally came up with a very effective way of achieving this cross-table column synchronization feature. It is actually functional in this REPL.
The problem: The calculation of the filler columns require setting state! Setting state while calculating a derived is currently forbidden. This forced the REPL to redefine
colDefs
as$state
which is updated in an$effect
. The terrible part of this is: My component would no longer be able to nicely server-render because effects don't run in SSR.Describe the proposed solution
Somehow allow state mutation from a $derived?? I have no other idea except allowing it. If anyone has a better solution, I'll welcome it.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: