Skip to content

Conversation

bosiraphael
Copy link
Contributor

Fixes an infinite loop introduced by #12371

An infinite loop was triggered when there was an error when fetching the client config.
Cause of the bug: isLoadedOnce wasn't set to true when catching an error in useClientConfig.

This effect then created an infinite loop inside ClientConfigProviderEffect because fetchClientConfig updated clientConfigApiStatus.isLoading but not isLoadedOnce.

useEffect(() => {
    if (
      !clientConfigApiStatus.isLoadedOnce &&
      !clientConfigApiStatus.isLoading
    ) {
      fetchClientConfig();
    }
  }, [
    clientConfigApiStatus.isLoadedOnce,
    clientConfigApiStatus.isLoading,
    fetchClientConfig,
  ]);

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Fixed an infinite loop in the client configuration fetching mechanism that occurred when API errors were encountered. The isLoadedOnce flag wasn't being set on errors, causing continuous refetch attempts.

  • Added isLoadedOnce: true in error state updates in useClientConfig.ts to properly terminate fetch cycles
  • Issue occurred in dependency array tracking of clientConfigApiStatus.isLoadedOnce and isLoading states
  • Previous implementation caused effect to re-trigger fetches indefinitely on API errors
  • Fix aligns with Recoil state management guidelines by ensuring proper state updates in error scenarios

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Jun 5, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:2877

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 2f89b36 into main Jun 5, 2025
52 of 54 checks passed
@charlesBochet charlesBochet deleted the r--fix-client-config-infinite-loop branch June 5, 2025 17:38
charlesBochet pushed a commit that referenced this pull request Jun 6, 2025
Fixes an infinite loop introduced by #12371

An infinite loop was triggered when there was an error when fetching the
client config.
Cause of the bug: `isLoadedOnce` wasn't set to true when catching an
error in `useClientConfig`.

This effect then created an infinite loop inside
`ClientConfigProviderEffect` because `fetchClientConfig` updated
`clientConfigApiStatus.isLoading` but not `isLoadedOnce`.

```typescript
useEffect(() => {
    if (
      !clientConfigApiStatus.isLoadedOnce &&
      !clientConfigApiStatus.isLoading
    ) {
      fetchClientConfig();
    }
  }, [
    clientConfigApiStatus.isLoadedOnce,
    clientConfigApiStatus.isLoading,
    fetchClientConfig,
  ]);
```
abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 10, 2025
Fixes an infinite loop introduced by twentyhq#12371

An infinite loop was triggered when there was an error when fetching the
client config.
Cause of the bug: `isLoadedOnce` wasn't set to true when catching an
error in `useClientConfig`.

This effect then created an infinite loop inside
`ClientConfigProviderEffect` because `fetchClientConfig` updated
`clientConfigApiStatus.isLoading` but not `isLoadedOnce`.

```typescript
useEffect(() => {
    if (
      !clientConfigApiStatus.isLoadedOnce &&
      !clientConfigApiStatus.isLoading
    ) {
      fetchClientConfig();
    }
  }, [
    clientConfigApiStatus.isLoadedOnce,
    clientConfigApiStatus.isLoading,
    fetchClientConfig,
  ]);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants