Skip to content

Conversation

@lucasbordeau
Copy link
Contributor

This PR solves small bugs around the view picker.

  • Couldn’t obtain optimistic update after a re-order of a view by drag and drop, we needed to refresh the page
  • Picking a new icon wouldn’t trigger optimistic update (same problem)
  • Picking a new icon would change the view (difficult to understand behavior)
  • Picking a new icon would trigger left drawer collapse (z-index problem)

Since core views are not being handled by object metadata items anymore, and that all view logic is plugged on coreViewsState, this PR implemented optimistic effect by upserting into this state.

Fixes #15422
Fixes #16986

Before

Enregistrement.de.l.ecran.2026-01-07.a.15.23.20.mov

After

Enregistrement.de.l.ecran.2026-01-07.a.15.29.09.mov

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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 15 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/twenty-front/src/modules/views/hooks/internal/useUpdateView.ts">

<violation number="1" location="packages/twenty-front/src/modules/views/hooks/internal/useUpdateView.ts:60">
P1: Missing rollback on mutation failure. The optimistic update is applied before the mutation (lines 31-38), but if the mutation fails, the state is never reverted to its original value. This causes UI/backend desync where the user sees the optimistic change but the backend has the original data.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

status: 'successful',
response: result,
};
} catch (error) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 7, 2026

Choose a reason for hiding this comment

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

P1: Missing rollback on mutation failure. The optimistic update is applied before the mutation (lines 31-38), but if the mutation fails, the state is never reverted to its original value. This causes UI/backend desync where the user sees the optimistic change but the backend has the original data.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-front/src/modules/views/hooks/internal/useUpdateView.ts, line 60:

<comment>Missing rollback on mutation failure. The optimistic update is applied before the mutation (lines 31-38), but if the mutation fails, the state is never reverted to its original value. This causes UI/backend desync where the user sees the optimistic change but the backend has the original data.</comment>

<file context>
@@ -0,0 +1,84 @@
+          status: 'successful',
+          response: result,
+        };
+      } catch (error) {
+        if (error instanceof ApolloError) {
+          handleMetadataError(error, {
</file context>
Fix with Cubic

Comment on lines 63 to 73
primaryMetadataName: 'view',
});
} else {
enqueueErrorSnackBar({ message: t`An error occurred.` });
}

return {
status: 'failed',
error,
};
}

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

🚀 Preview Environment Ready!

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

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

@@ -91,39 +88,6 @@ export const usePersistView = () => {
],
);

const updateView = useCallback(
Copy link
Member

Choose a reason for hiding this comment

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

I would leave it in usePersistView

Current naming convention:

  • persistViewFilter = create, update, delete in backend
  • saveViewFilter = transform the recordFilters to viewFilters and call persistViewFilter
  • remove / upsertRecordFilter = update record filters

Copy link
Member

Choose a reason for hiding this comment

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

New naming proposal:

  • performViewFilterAPICreate / performViewFilterAPIUpdate / performViewFilterAPIUpdate viewFilter => wrapping of api calls
  • saveRecordFiltersToViewFilters
  • upsert / remove recordFilter => update recordFilters state

Copy link
Member

Choose a reason for hiding this comment

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

so this hook should performViewAPIUpdate

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 28 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIUpdate.ts">

<violation number="1" location="packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIUpdate.ts:61">
P1: Missing rollback of optimistic update on error. If `updateCoreViewMutation` fails, the UI will still show the optimistically applied changes that weren't persisted to the server. Store the previous state before applying the optimistic update and restore it in the catch block.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

status: 'successful',
response: result,
};
} catch (error) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 8, 2026

Choose a reason for hiding this comment

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

P1: Missing rollback of optimistic update on error. If updateCoreViewMutation fails, the UI will still show the optimistically applied changes that weren't persisted to the server. Store the previous state before applying the optimistic update and restore it in the catch block.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIUpdate.ts, line 61:

<comment>Missing rollback of optimistic update on error. If `updateCoreViewMutation` fails, the UI will still show the optimistically applied changes that weren't persisted to the server. Store the previous state before applying the optimistic update and restore it in the catch block.</comment>

<file context>
@@ -0,0 +1,86 @@
+          status: 'successful',
+          response: result,
+        };
+      } catch (error) {
+        if (error instanceof ApolloError) {
+          handleMetadataError(error, {
</file context>
Fix with Cubic

@charlesBochet charlesBochet disabled auto-merge January 8, 2026 11:05
@charlesBochet charlesBochet merged commit e9b7ad2 into main Jan 8, 2026
72 of 74 checks passed
@charlesBochet charlesBochet deleted the fix/view-picker-optimistic-effect branch January 8, 2026 11:05
@twenty-eng-sync
Copy link

Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

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.

Re-ordering a view in the view picker does not work [Views] - Editing the icon of the view is no longer shown immediately

3 participants