Skip to content

How "written in stone" is the rule about not changing state in $derived? #14793

Closed as not planned
@webJose

Description

@webJose

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions