equinor / mad

Experimental monorepo for the Mobile Application Delivery team

Home Page:https://equinor.github.io/mad/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Updating the state of a cell causes all cells in cellgroup to re render

HavardNot opened this issue · comments

Package / App

MAD Components

Version

0.13.0

What happened?

Expected behaviour: When the state of a cell is updated, only the current cell should be re-rendered
Actual behaviour: All cells in the cell group are re-rendered.

When working with large cell groups this causes slowness in the app. This can probably be fixed by using memoization

Other info

No response

Relevant log output

No response

@HavardNot I tried recreating this by creating a simple test screen:

const StateCell = () => {
    const renderCounter = useRef(0);
    renderCounter.current += 1;
    const [myState, setMyState] = useState<number>(0);

    return (
        <Cell style={{}}>
            <Typography>Rendered {renderCounter.current} times</Typography>
            <Button title="Cause rerender" onPress={() => setMyState(state => state + 1)} />
        </Cell>
    );
};


export const TestScreen = () => {
    const style = useStyles(themeStyles);
    return (
        <ScrollView
            contentInsetAdjustmentBehavior="automatic"
            contentContainerStyle={style.contentContainer}
        >
            <Cell.Group>
                <StateCell />
                <StateCell />
                <StateCell />
            </Cell.Group>
        </ScrollView>
    );
};

const themeStyles = EDSStyleSheet.create(theme => ({
    contentContainer: {
        paddingVertical: theme.spacing.container.paddingVertical,
    },
}));

And got the following results:

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.DEV.-.2024-03-26.at.08.17.19.mp4

It seems that state changes inside single cells do not cause others to rerender. Was this what you meant, or was the issue you described triggered by something else?

@HaakonSvane I was having this issue using it for Country Information, but I was struggling to reproduce the issue in Chronicles. @tormodAase did you take a look at this, and did you manage to reproduce the problem?

Nope, I can try to reproduce the issue this week