Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/components/Connections/CreateConnectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,15 @@ const CreateConnectionForm = ({
: stream.destinationSyncMode;

if (!checked) {
stream.cursorField = '';
stream.primaryKey = [];
if (!stream.cursorFieldConfig.sourceDefinedCursor) {
// Reset to empty cursor field if not source-defined
stream.cursorField = '';
}

if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
// Reset primary key to empty array if not source-defined
stream.primaryKey = [];
}
Comment on lines +423 to +431
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid mutating React state objects in-place; compute next values and update immutably

Directly mutating stream before calling updateThisStreamTo_ risks subtle bugs and stale renders. Compute the next values and pass them in a single immutable update.

Apply this diff to make the update atomic and immutable:

-    if (!checked) {
-      if (!stream.cursorFieldConfig.sourceDefinedCursor) {
-        // Reset to empty cursor field if not source-defined
-        stream.cursorField = '';
-      }
-
-      if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
-        // Reset primary key to empty array if not source-defined
-        stream.primaryKey = [];
-      }
-    }
-
-    updateThisStreamTo_(stream, {
-      ...stream,
-      syncMode: checked ? 'incremental' : 'full_refresh',
-      destinationSyncMode: destinationMode,
-    });
+    const nextCursorField =
+      !checked && !stream.cursorFieldConfig.sourceDefinedCursor ? '' : stream.cursorField;
+    const nextPrimaryKey =
+      !checked && !stream.primaryKeyConfig.sourceDefinedPrimaryKey ? [] : stream.primaryKey;
+
+    updateThisStreamTo_(stream, {
+      ...stream,
+      syncMode: checked ? 'incremental' : 'full_refresh',
+      destinationSyncMode: destinationMode,
+      cursorField: nextCursorField,
+      primaryKey: nextPrimaryKey,
+    });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!stream.cursorFieldConfig.sourceDefinedCursor) {
// Reset to empty cursor field if not source-defined
stream.cursorField = '';
}
if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
// Reset primary key to empty array if not source-defined
stream.primaryKey = [];
}
const nextCursorField =
!checked && !stream.cursorFieldConfig.sourceDefinedCursor ? '' : stream.cursorField;
const nextPrimaryKey =
!checked && !stream.primaryKeyConfig.sourceDefinedPrimaryKey ? [] : stream.primaryKey;
updateThisStreamTo_(stream, {
...stream,
syncMode: checked ? 'incremental' : 'full_refresh',
destinationSyncMode: destinationMode,
cursorField: nextCursorField,
primaryKey: nextPrimaryKey,
});
🤖 Prompt for AI Agents
In src/components/Connections/CreateConnectionForm.tsx around lines 423 to 431,
avoid mutating the stream object in-place; instead compute the next stream
object immutably and call updateThisStreamTo_ once with that object. Concretely,
build a newStream = { ...stream, cursorField:
stream.cursorFieldConfig.sourceDefinedCursor ? stream.cursorField : '',
primaryKey: stream.primaryKeyConfig.sourceDefinedPrimaryKey ? stream.primaryKey
: [] } (ensuring any nested objects are spread as needed) and pass newStream to
updateThisStreamTo_ so the update is atomic and no in-place mutation occurs.

}

updateThisStreamTo_(stream, {
Expand All @@ -431,9 +438,6 @@ const CreateConnectionForm = ({
});
};
const setDestinationSyncMode = (value: string, stream: SourceStream) => {
if (value != 'append_dedup') {
stream.primaryKey = [];
}
updateThisStreamTo_(stream, { ...stream, destinationSyncMode: value });
};

Expand Down