Skip to content

fix(evalTree): guard against empty parsed updates array - #42042

Closed
PedroHenrique0713 wants to merge 3 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/evaltree-widget
Closed

fix(evalTree): guard against empty parsed updates array#42042
PedroHenrique0713 wants to merge 3 commits into
appsmithorg:releasefrom
PedroHenrique0713:fix/evaltree-widget

Conversation

@PedroHenrique0713

@PedroHenrique0713 PedroHenrique0713 commented Jul 23, 2026

Copy link
Copy Markdown

Empty evaluation tree → parsedUpdates [0] → TypeError. Guard with .length check.

Summary by CodeRabbit

  • Bug Fixes

    • Improved stability when evaluating form expressions that contain errors.
    • Prevented failures when newly created data trees have no updates.
    • Ensured configuration entries with evaluation errors remain unchanged.
  • Refactor

    • Added clearer documentation around how object cloning handles special data types and functions.

  When evaluation produced an empty tree, parsedUpdates[0] was undefined
  and accessing .rhs threw TypeError. Now checks .length before access.
@PedroHenrique0713
PedroHenrique0713 requested a review from a team as a code owner July 23, 2026 21:24
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Evaluation worker code now documents failed expression and JSON cloning behavior, while guarding previous-state updates when tree parsing produces no updates.

Changes

Evaluation safety

Layer / File(s) Summary
Evaluation runtime and serialization handling
app/client/src/workers/Evaluation/formEval.ts, app/client/src/workers/Evaluation/handlers/evalTree.ts, app/client/src/workers/Evaluation/helpers.ts
Failed form expressions leave the specific entry’s output unchanged, empty parsed tree updates no longer access index zero, and JSON cloning behavior in stringifyFnsInObject is documented.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

Poem

Empty updates find no risky state,
Failed expressions quietly wait.
JSON sheds types along its flight,
Functions return in string form bright.
Safer workers hum through the night.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too sparse and omits required template sections like Fixes, Automation/Cypress results, and Communication. Expand the PR description to match the template: add motivation/context, a Fixes issue number or URL, the Automation/Cypress sections, and the Communication checkbox.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: guarding evalTree against empty parsedUpdates.
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

🤖 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/workers/Evaluation/helpers.ts`:
- Around line 114-116: Update the serialization comment near fnValue.toString()
to state that functions are converted to source strings and reinserted as
strings, not preserved as callable functions. Describe the handling of
non-JSON-safe values as potentially lossy conversions, rather than claiming all
such types are stripped.
🪄 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: 8f450c2b-1c29-410a-bf7c-688a5485789f

📥 Commits

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

📒 Files selected for processing (3)
  • app/client/src/workers/Evaluation/formEval.ts
  • app/client/src/workers/Evaluation/handlers/evalTree.ts
  • app/client/src/workers/Evaluation/helpers.ts

Comment on lines +114 to +116
// Note: JSON round-trip strips Dates, Sets, Maps, RegExps, and undefined values.
// Functions are preserved (collected before, re-injected after), but other
// non-JSON-safe types may be lost.

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Clarify that functions are serialized as strings, not preserved as functions.

fnValue.toString() followed by set(...) reinserts function source text, so consumers cannot call the restored value as a function. Also describe the type conversions as lossy rather than saying every type is stripped.

Suggested wording
-  // Note: JSON round-trip strips Dates, Sets, Maps, RegExps, and undefined values.
-  // Functions are preserved (collected before, re-injected after), but other
-  // non-JSON-safe types may be lost.
+  // Note: JSON round-trip loses non-JSON-safe values; for example, Dates become
+  // strings, Sets/Maps/RegExps lose their original types, and undefined values
+  // are omitted or converted to null. Functions are re-injected as source strings.
📝 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
// Note: JSON round-trip strips Dates, Sets, Maps, RegExps, and undefined values.
// Functions are preserved (collected before, re-injected after), but other
// non-JSON-safe types may be lost.
// Note: JSON round-trip loses non-JSON-safe values; for example, Dates become
// strings, Sets/Maps/RegExps lose their original types, and undefined values
// are omitted or converted to null. Functions are re-injected as source strings.
🤖 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/workers/Evaluation/helpers.ts` around lines 114 - 116, Update
the serialization comment near fnValue.toString() to state that functions are
converted to source strings and reinserted as strings, not preserved as callable
functions. Describe the handling of non-JSON-safe values as potentially lossy
conversions, rather than claiming all such types are stripped.

@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