mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
ea31154d9a
This PR fixes an error where useSWR would throw a TypeError: `subs[i] is not a function`: https://github.com/vercel/swr/issues/2357 I can't be totally sure why this is happening but we had a design flaw in our setup that caused our group overview to first fetch all groups, and then subsequently fetch each individual group after the groups were rendered. This was happening because GroupCard was rendering the EditGroupUsers component which used the `useGroup(groupId)` getter. The flow in the old version looked like this: 1. Fetch all the groups 2. Use the groups data to render all the `GroupCard` elements 3. Once the GroupCard was rendered the EditGroupComponent would be mounted and set up a recurring GET on the individual group, causing each group to be fetched recurringly in the Group overview. The useSWR error seems to be connected to setting up these subscriptions, and then removing the element from the DOM. We were able to trigger this error by removing the group. ## How did we fix it? We refactored the components concerned with editing group users and removing groups to exist outside of the `GroupCard` and have the group card supply the base data through a state setter. This pattern is also better for the remove functionality because the remove functionality in its current state could trigger a react update on a component removed from the DOM if you awaited the refetching of the data. This is because the groups data is controlling the rendering of the `GroupCard` and when the `RemoveGroup` modal is nested underneath the `GroupCard` a refetch would trigger an update, re-render the overview and remove the entire `GroupCard` and the associated `RemoveGroup` component. I'm still not sure if this is a bug with SWR or a side-effect of how we architected the functionality, but this change seems to remove the problem. |
||
---|---|---|
.. | ||
SidebarModal.tsx |