Skip to content

fix: retryPromise silent failure and areArraysEqual false positives - #42035

Closed
PedroHenrique0713 wants to merge 2 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/retry-and-array-fixes
Closed

fix: retryPromise silent failure and areArraysEqual false positives#42035
PedroHenrique0713 wants to merge 2 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/retry-and-array-fixes

Conversation

@PedroHenrique0713

@PedroHenrique0713 PedroHenrique0713 commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Two bug fixes in Appsmith utility code.

1. retryPromise hangs forever when retries exhausted (AppsmithUtils.tsx)

Inside the setTimeout callback, Promise.reject(...) was used instead of reject(...). Since setTimeout ignores its callback's return value, the rejection never reached the outer Promise's reject handler. The promise hung forever when retries were exhausted. Fix: use reject() directly.

2. areArraysEqual false positives with comma-containing elements (AppsmithUtils.tsx)

Using join(",") to compare arrays means ["a,b"] and ["a","b"] are incorrectly reported as equal when the comma in the data collides with the delimiter. Fix: compare elements directly with .every().

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of names containing special characters to prevent incorrect duplicate-name detection.
    • Prevented visibility and scrolling errors when elements have no measurable area or widgets are unavailable.
    • Improved array comparison reliability.
    • Refined retry failure handling for more consistent error reporting.

… 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).
@PedroHenrique0713
PedroHenrique0713 requested a review from a team as a code owner July 23, 2026 19:36
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Utility functions now handle regex-special prefixes, compare arrays element-wise, preserve terminal retry errors, and guard scroll calculations against zero-area elements and missing widgets.

Changes

Utility Defensive Corrections

Layer / File(s) Summary
Utility matching, retry, and equality behavior
app/client/src/utils/AppsmithUtils.tsx
Name-generation regexes now escape prefixes, retry failure uses a direct error object, and array equality compares sorted elements individually.
Scroll and visibility guards
app/client/src/utils/helpers.tsx
Visibility checks return false for zero-area elements, while widget scrolling returns null for missing widgets.

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

Possibly related PRs

Poem

Regex stars now tread with care,
Arrays compare pair by pair,
Empty widgets softly bow,
Zero areas halt somehow,
Retry errors land fair and square.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives a useful summary but does not follow the required template or include the Fixes, Automation, or Communication sections. Reformat the PR body to match the template, add the issue link or number, Automation notes, Cypress results, and the Communication checkbox.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main fixes in retryPromise and areArraysEqual.
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 (1)
app/client/src/utils/AppsmithUtils.tsx (1)

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

Sort arr2 only once.

[...arr2].sort() currently runs for every element of arr1, causing repeated allocations and unnecessary O(n² log n) work. Copy and sort both arrays before calling every().

Proposed fix
-  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 in the surrounding utility function to copy and sort both arr1
and arr2 once before invoking every(). Reuse the sorted arr2 inside the every
callback while preserving the existing element-by-element equality behavior.
🤖 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/AppsmithUtils.tsx`:
- Around line 321-326: Update the terminal error handling in the React.lazy
loading flow to reject the outer promise with the caught error `e`, preserving
its original stack and payload. If UI metadata is required, attach it while
retaining `e` rather than replacing it with a new SERVER_ERROR object.

---

Nitpick comments:
In `@app/client/src/utils/AppsmithUtils.tsx`:
- Line 442: Update the array comparison logic in the surrounding utility
function to copy and sort both arr1 and arr2 once before invoking every(). Reuse
the sorted arr2 inside the every callback while preserving the existing
element-by-element equality behavior.
🪄 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: c454ca09-673a-41b0-a774-cc9b92f6dc9f

📥 Commits

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

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

Comment on lines +321 to +326
reject({
code: ERROR_CODES.SERVER_ERROR,
message: createMessage(ERROR_500),
show: false,
});
return;

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

Preserve the terminal retry error.

The caught e is discarded and replaced with a new object, so React.lazy and downstream error boundaries lose the original module-load error, stack, and payload. Reject the outer promise with e (or retain it as the cause while adding the UI metadata).

Proposed fix
-              reject({
-                code: ERROR_CODES.SERVER_ERROR,
-                message: createMessage(ERROR_500),
-                show: false,
-              });
+              reject(e);
📝 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
reject({
code: ERROR_CODES.SERVER_ERROR,
message: createMessage(ERROR_500),
show: false,
});
return;
reject(e);
return;
🤖 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` around lines 321 - 326, Update the
terminal error handling in the React.lazy loading flow to reject the outer
promise with the caught error `e`, preserving its original stack and payload. If
UI metadata is required, attach it while retaining `e` rather than replacing it
with a new SERVER_ERROR object.

@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