graasp / graasp-player

GNU Affero General Public License v3.0
0 stars 2 forks source link

feat(deps): update query-client to use v5 #848

Closed ReidyT closed 1 week ago

ReidyT commented 1 month ago

Since the Query v5 doesn't fill the cache from descendants and other queries, the useItem is empty on first render, potentially causing a re-render of the three.

https://github.com/user-attachments/assets/697b53dc-35cc-490e-b9bf-eb8f444d0ee5

https://github.com/user-attachments/assets/9f911b5e-0dbd-42b8-87ae-2f5ed39d9693

https://github.com/user-attachments/assets/f18e5ac8-3b30-4f44-a3de-8d6673b27aa5

Indeed, this re-render is removed when setting the following placeholder for the useItem:

placeholderData: options?.placeholderData
          ? options?.placeholderData
          : () =>
              queryClient
                .getQueryData<
                  PackedItem[]
                >(itemKeys.single('54f33535-ce3b-4610-9c7d-43f6f3b54524').descendants({ types: ['folder'], showHidden: false }))
                ?.find((i) => i.id === id),

The problem is we cannot always get the item's data from another cache because it depend on the view (sometimes from descendants, children, etc and the filters aren't always the same). Moreover, it's not possible to retrieve the parent id only from the given item's id and the cache.

ReidyT commented 3 weeks ago

To solve this issue, I used the keepPreviousState function in the placeholder. This avoids the unwanted re-render with undefined value when fetching new data.

There is still a small issue on very small network, we have to check if it's acceptable or not.

https://github.com/user-attachments/assets/d14b121d-a2e0-4079-bec3-6124e4b912ac

ReidyT commented 3 weeks ago

Thanks to @spaenleh, the simplest way to fix this issue, is to derivate the focusedItem from the itemsToShow.

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
42.9% Duplication on New Code

See analysis details on SonarCloud