Skip to content

fix: pushToArray mutation and getPathAndValueFromActionDiffObject logic errors - #42036

Closed
PedroHenrique0713 wants to merge 3 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/push-to-array-and-diff
Closed

fix: pushToArray mutation and getPathAndValueFromActionDiffObject logic errors#42036
PedroHenrique0713 wants to merge 3 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/push-to-array-and-diff

Conversation

@PedroHenrique0713

@PedroHenrique0713 PedroHenrique0713 commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Two bug fixes in Appsmith utilities.

1. pushToArray mutates input array in-place (helpers.tsx)

arr1.push(item) mutates the caller's array, which is unexpected for a utility function in a Redux-based app. Frozen arrays would throw. Other helpers like concatWithArray use .concat() — this one was inconsistent. Fix: spread-copy and append.

2. getPathAndValueFromActionDiffObject logic errors (getPathAndValueFromActionDiffObject.ts)

Two bugs: (a) the reduce callback referenced the outer path variable instead of acc, so for multi-segment paths the accumulator grew incorrectly; (b) the return { path, value } was inside the for loop, exiting after the first iteration regardless of whether a kind === "N" diff was found. Fix: use acc consistently and move return outside the loop.

Summary by CodeRabbit

  • Bug Fixes
    • Improved automatic naming for entities and duplicates containing special characters.
    • Standardized error handling when retries are exhausted.
    • Improved array comparison accuracy and safer array updates.
    • Corrected visibility checks for zero-size elements.
    • Improved widget scrolling when a requested widget cannot be found.
    • Fixed detection and handling of newly added changes in action differences.

… lookup

fix(AppsmithUtils): escape regex special characters in getNextEntityName and
getDuplicateName. Entity name prefixes containing regex metacharacters (. $ * + etc.)
caused incorrect auto-increment numbering and potential name collisions.

fix(helpers): guard against division by zero in isElementVisibleInContainer.
When an element has zero dimensions, elementArea === 0 caused Infinity/NaN
comparisons that falsely reported the element as visible.

fix(helpers): add null guard to getWidgetElementToScroll.
Accessing widget.parentId without checking if canvasWidgets[widgetId]
exists caused TypeError on stale/deleted widget IDs.
fix(retryPromise): use reject() instead of Promise.reject() inside setTimeout.
  The setTimeout callback return value is ignored, so Promise.reject() created
  a dangling rejection that never reached the outer Promise's reject handler,
  causing the promise to hang forever when retries were exhausted.

fix(areArraysEqual): use element-wise comparison instead of join(",").
  Array elements containing commas caused false positives (e.g.,
  ["a,b"] and ["a","b"] incorrectly reported as equal).
fix(helpers): pushToArray no longer mutates input array in-place.
  Previously arr1.push(item) mutated the caller's array, violating
  immutability expectations in Redux state. Now creates a new array.

fix(getPathAndValueFromActionDiffObject): fix reduce accumulator path
  computation and early return. The reduce callback referenced the outer
  'path' variable instead of 'acc', causing path to grow incorrectly
  across multiple diff elements. The return statement was also inside
  the for loop, exiting prematurely instead of checking all elements.
@PedroHenrique0713
PedroHenrique0713 requested a review from a team as a code owner July 23, 2026 19:37
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Utility functions now escape regex prefixes, improve retry rejection, compare arrays element-wise, construct diff paths from accumulator state, guard empty or missing DOM targets, and avoid mutating arrays.

Changes

Utility correctness

Layer / File(s) Summary
Name and comparison utilities
app/client/src/utils/AppsmithUtils.tsx
Name matching escapes regex prefixes, terminal retry failures call reject directly, and array equality compares sorted copies element by element.
Diff path extraction
app/client/src/utils/getPathAndValueFromActionDiffObject.ts
String path segments use accumulator state for dot notation, and matching new entries return immediately.
Helper safety and array construction
app/client/src/utils/helpers.tsx
Zero-area elements and missing widgets return safely, while pushToArray creates arrays without mutating its input.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

Regex sparks are tamed tonight,
Paths find their endings right.
Arrays rest, untouched and new,
Missing widgets safely pass through.
Tiny helpers march in tune.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the bug fixes but omits required template sections like Fixes, Automation, Cypress results, and Communication. Add the full template sections, including issue reference, /ok-to-test tag, Cypress results, and the Communication checkbox.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the two primary fixes and matches the main changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/client/src/utils/AppsmithUtils.tsx (1)

442-442: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Sort each array only once.

[...arr2].sort() runs for every element checked by every, creating unnecessary O(n² log n) work for larger selections.

Proposed fix
 export function areArraysEqual(arr1: string[], arr2: string[]) {
   if (arr1.length !== arr2.length) return false;

   // Because the array is frozen in strict mode, you'll need to copy the array before sorting it
-  return [...arr1].sort().every((val, i) => val === [...arr2].sort()[i]);
+  const sortedArr1 = [...arr1].sort();
+  const sortedArr2 = [...arr2].sort();
+  return sortedArr1.every((val, i) => val === sortedArr2[i]);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/client/src/utils/AppsmithUtils.tsx` at line 442, Update the array
comparison logic around the return expression to sort both copied arrays once
before calling every, then compare the pre-sorted values by index. Preserve the
existing non-mutating behavior and equality semantics while avoiding repeated
sorting of arr2.
app/client/src/utils/helpers.tsx (1)

1320-1324: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Audit pushToArray call sites for side-effect-only usage.

The only runtime call site currently assigns the returned value, but side-effect-only callers would silently stop updating their arrays after this non-mutating update. Also add a test asserting that the original arr1 remains unchanged.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/client/src/utils/helpers.tsx` around lines 1320 - 1324, Audit all runtime
call sites of pushToArray for callers that rely on mutation without using its
return value, and update those callers to assign the returned array or otherwise
preserve their behavior. Add a test covering the pushToArray behavior where the
original arr1 remains unchanged after the call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/client/src/utils/getPathAndValueFromActionDiffObject.ts`:
- Around line 63-66: Update getPathAndValueFromActionDiffObject so the loop
continues scanning every diff entry instead of returning when the first kind ===
"N" entry is found. Keep updating the path and value accumulator for matching
entries, then return { path, value } only after iteration completes.

---

Nitpick comments:
In `@app/client/src/utils/AppsmithUtils.tsx`:
- Line 442: Update the array comparison logic around the return expression to
sort both copied arrays once before calling every, then compare the pre-sorted
values by index. Preserve the existing non-mutating behavior and equality
semantics while avoiding repeated sorting of arr2.

In `@app/client/src/utils/helpers.tsx`:
- Around line 1320-1324: Audit all runtime call sites of pushToArray for callers
that rely on mutation without using its return value, and update those callers
to assign the returned array or otherwise preserve their behavior. Add a test
covering the pushToArray behavior where the original arr1 remains unchanged
after the call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c2c5bde-8dc3-4be8-bf08-c09d5f643496

📥 Commits

Reviewing files that changed from the base of the PR and between 583811d and 2aaed07.

📒 Files selected for processing (3)
  • app/client/src/utils/AppsmithUtils.tsx
  • app/client/src/utils/getPathAndValueFromActionDiffObject.ts
  • app/client/src/utils/helpers.tsx

Comment on lines +63 to +66
return { path, value };
}

return { path, value };
}
return { path, value };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Return only after scanning all diff entries.

Returning inside the loop stops at the first kind === "N" entry, so later changes are ignored and the final return is unreachable for matching diffs. Keep updating the accumulator during iteration and return { path, value } after the loop, as required by the diff-extraction objective.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/client/src/utils/getPathAndValueFromActionDiffObject.ts` around lines 63
- 66, Update getPathAndValueFromActionDiffObject so the loop continues scanning
every diff entry instead of returning when the first kind === "N" entry is
found. Keep updating the path and value accumulator for matching entries, then
return { path, value } only after iteration completes.

@PedroHenrique0713

Copy link
Copy Markdown
Author

Closing this one. I opened a stack of PRs in this repo today and, because each branch was cut from the previous one instead of from the base, they overlap: this PR carries the commits of the earlier ones as well. I am consolidating the work in #42033 and will resubmit the remaining fixes individually, on top of the base branch, once that one has been reviewed. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant