Expensify / react-native-onyx

Persistent, offline-first state management solution for React Native. Easy to use with minimal config and boilerplate.
MIT License
151 stars 71 forks source link

Add snapshot functionality #552

Closed jnowakow closed 3 months ago

jnowakow commented 3 months ago

Details

This PR adds snapshot functionality described in design doc. It adds special support for SNAPSHOT key. Objects inside its data field will be updated with every change made through update function.

Related Issues

https://github.com/Expensify/App/issues/41626

Automated Tests

Manual Tests

  1. Open Search Page.
  2. View any transaction.
  3. Modify amount
  4. Check if value was updated in table

Author Checklist

Screenshots/Videos

Android: Native https://github.com/Expensify/react-native-onyx/assets/56261019/10a934db-4d85-4f45-9b16-4b96ad51dc8b
Android: mWeb Chrome https://github.com/Expensify/react-native-onyx/assets/56261019/f62863e7-a3a1-466d-b686-8cfa635a00f5
iOS: Native https://github.com/Expensify/react-native-onyx/assets/56261019/ee8e10f2-1a7b-4e61-b5d7-446204887de2
iOS: mWeb Safari https://github.com/Expensify/react-native-onyx/assets/56261019/4d3ecc3f-8ac6-4b3f-8084-0614e9d4b850
MacOS: Chrome / Safari https://github.com/Expensify/react-native-onyx/assets/56261019/dc1c3af3-e6cf-47ce-832c-ea5bb18d2561
MacOS: Desktop https://github.com/Expensify/react-native-onyx/assets/56261019/fc51d7e0-1730-4b71-a171-762c50d3b300
github-actions[bot] commented 3 months ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

jnowakow commented 3 months ago

I have read the CLA Document and I hereby sign the CLA

allroundexperts commented 3 months ago

Reviewer Checklist

Screenshots/Videos

Android: Native N/A
Android: mWeb Chrome https://github.com/Expensify/react-native-onyx/assets/30054992/39ef66ab-8704-456c-a3ae-841dd57dab52
iOS: Native N/A
iOS: mWeb Safari https://github.com/Expensify/react-native-onyx/assets/30054992/e0b84a65-a853-4380-99c4-6fc5735415ae
MacOS: Chrome / Safari https://github.com/Expensify/react-native-onyx/assets/30054992/6a1fc46f-1be5-4606-b9c6-e489c8931ae5
MacOS: Desktop https://github.com/Expensify/react-native-onyx/assets/30054992/5708d7a2-c43a-49f0-9830-93aa2ad62110
allroundexperts commented 3 months ago

Yep, I'm on it!

trjExpensify commented 3 months ago

How you getting on @allroundexperts?

allroundexperts commented 3 months ago

@trjExpensify I was unable to verify the fix. For me, the table values do not get updated.

allroundexperts commented 3 months ago

https://github.com/Expensify/react-native-onyx/assets/30054992/424a4298-8e8e-49ed-9ff5-dceb86ad2268

luacmartins commented 3 months ago

@allroundexperts just confirming that you updated App to use this branch of Onyx?

allroundexperts commented 3 months ago

@luacmartins Yes, I checked out this branch and built it using npm run build. After that, I copied the dist folder and replaced it inside the node_modules of the main app.

allroundexperts commented 3 months ago

@Kicu Any update on above?

jnowakow commented 3 months ago

@allroundexperts I'm investigating it. It's strange because it seems that there is problem with updating component since data in onyx are updated: image

I checkout out also version before optimisation and it works the same. I'll dig into it further

jnowakow commented 3 months ago

@allroundexperts problem lies in App. Two days ago this PR was merged. It wraps all components in Search table in memo. The problem is that function passed to memo checks only keyForList. So even if amount changes the component isn't re-rendered and shows outdated value.

For testing purposes you can modify TotalCell component like this:

const TotalCell = memo(({showTooltip, amount, currency, isLargeScreenWidth}: CurrencyCellProps) => {
    const styles = useThemeStyles();

    return (
        <TextWithTooltip
            shouldShowTooltip={!!showTooltip}
            text={CurrencyUtils.convertToDisplayString(amount, currency)}
            style={[styles.optionDisplayName, styles.textNewKansasNormal, styles.pre, styles.justifyContentCenter, isLargeScreenWidth ? undefined : styles.textAlignRight]}
        />
    );
});

It's defined in src/components/SelectionList/Search/TransactionListItemRow.tsx file.

Go-to solution is to modify functions passed to memo because other cells won't update if they props change cc @luacmartins

luacmartins commented 3 months ago

Nice find @jnowakow! Yea, let's update the prop comparison function to handle these updates too!

jnowakow commented 3 months ago

@luacmartins sure thing! I'll work on that. Should I create issue for this?

luacmartins commented 3 months ago

@jnowakow created issue here

luacmartins commented 3 months ago

@allroundexperts were you able to test following @jnowakow's instructions here?

allroundexperts commented 3 months ago

Not really. Isn't this on hold?

luacmartins commented 3 months ago

I think just a merge hold. We can still continue development. What part of the instructions didn't work?

allroundexperts commented 3 months ago

Oh, I didn't continue the testing after hold was applied. Will re-test and get back today.

allroundexperts commented 3 months ago

Just tested this again. The new search page seems to be broken now 😞

https://github.com/Expensify/react-native-onyx/assets/30054992/3885ab45-862d-4675-8cb9-f58085d0d9dd

luacmartins commented 3 months ago

@allroundexperts yea, we messed up the API a bit. To temporarily fix it you can change this value to transactions instead of transaction

allroundexperts commented 3 months ago

@luacmartins It works now. But on Android, I'm getting the following crash:

https://github.com/Expensify/react-native-onyx/assets/30054992/3e4eeb58-0ca9-4edb-ba30-1ae35a24d50d

luacmartins commented 3 months ago

@allroundexperts that seems unrelated to this PR. Can we focus testing this Onyx changes in Web first? We should be able to see the live updates in Search when they are edited.

allroundexperts commented 3 months ago

@allroundexperts that seems unrelated to this PR. Can we focus testing this Onyx changes in Web first? We should be able to see the live updates in Search when they are edited.

I can confirm that for web, it is working fine.

allroundexperts commented 3 months ago

Working on the checklist now.

luacmartins commented 3 months ago

The holding PR was merged, we can remove the hold here

github-actions[bot] commented 3 months ago

🚀Published to npm in v2.0.49