Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: JSONForm infinite re-rendering when field validation is set #35994

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

ashit-rath
Copy link
Contributor

@ashit-rath ashit-rath commented Aug 30, 2024

Description

The setError function updates the state and the effect is also dependant on the state which triggers re-render. This is a classic case of re-rendering due to self state dependency and is fixed with a check if the error is present for a particular field then it doesn't need to set again

Fixes #35995

Automation

/ok-to-test tags="@tag.JSONForm"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10627924838
Commit: 1d5dec6
Cypress dashboard.
Tags: @tag.JSONForm
Spec:


Fri, 30 Aug 2024 06:50:40 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced error handling logic in the form validation process to improve efficiency and correctness.
  • Tests

    • Added a new test case to validate the behavior of the form validation hook when encountering invalid field states.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes involve enhancements to the useRegisterFieldValidity hook and its corresponding tests. A new test case has been added to evaluate the hook's behavior when the isValid parameter is set to false without an existing error. Additionally, the error handling logic within the hook has been modified to conditionally invoke the setError function only when no error is present, improving the efficiency of error management.

Changes

File Path Change Summary
app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts Modified error handling logic to conditionally call setError only when no existing error is present.
app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.test.tsx Added a new test case to check the behavior of useRegisterFieldValidity when isValid is false and no error exists.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Form
    participant Hook
    participant ErrorHandler

    User->>Form: Submit invalid data
    Form->>Hook: Call useRegisterFieldValidity(isValid: false)
    Hook->>ErrorHandler: Check for existing error
    alt No existing error
        ErrorHandler-->>Hook: setError() called
    else Existing error present
        ErrorHandler-->>Hook: No action taken
    end
Loading

In the realm of code, a change took flight,
To manage errors with newfound light.
A test was born, to check and ensure,
That validity's path was clear and pure.
With logic refined, and flows so neat,
The form now dances, a rhythm complete!
🌟✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ashit-rath ashit-rath self-assigned this Aug 30, 2024
@ashit-rath ashit-rath added the ok-to-test Required label for CI label Aug 30, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between abce472 and 1d5dec6.

Files selected for processing (2)
  • app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.test.tsx (1 hunks)
  • app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts (1 hunks)

@github-actions github-actions bot added JSON Form Issue / features related to the JSON form wiget Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Aug 30, 2024
@ashit-rath
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10628129558.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35994.
recreate: .

@ashit-rath ashit-rath changed the title perf: JSONForm infinite function when setting internal error state when a field has error perf: JSONForm infinite re-rendering when field validation is set Aug 30, 2024
Copy link

Deploy-Preview-URL: https://ce-35994.dp.appsmith.com

@ashit-rath ashit-rath merged commit 827f22e into release Aug 30, 2024
55 checks passed
@ashit-rath ashit-rath deleted the fix/jsonform-seterror-infinite-loop branch August 30, 2024 11:14
ashit-rath added a commit that referenced this pull request Aug 30, 2024
…5994)

## Description
The setError function updates the state and the effect is also dependant
on the state which triggers re-render. This is a classic case of
re-rendering due to self state dependency and is fixed with a check if
the error is present for a particular field then it doesn't need to set
again

Fixes #35995

## Automation

/ok-to-test tags="@tag.JSONForm"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10627924838>
> Commit: 1d5dec6
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10627924838&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JSONForm`
> Spec:
> <hr>Fri, 30 Aug 2024 06:50:40 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced error handling logic in the form validation process to
improve efficiency and correctness.
  
- **Tests**
- Added a new test case to validate the behavior of the form validation
hook when encountering invalid field states.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
…psmithorg#35994)

## Description
The setError function updates the state and the effect is also dependant
on the state which triggers re-render. This is a classic case of
re-rendering due to self state dependency and is fixed with a check if
the error is present for a particular field then it doesn't need to set
again

Fixes appsmithorg#35995

## Automation

/ok-to-test tags="@tag.JSONForm"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10627924838>
> Commit: 1d5dec6
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10627924838&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JSONForm`
> Spec:
> <hr>Fri, 30 Aug 2024 06:50:40 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced error handling logic in the form validation process to
improve efficiency and correctness.
  
- **Tests**
- Added a new test case to validate the behavior of the form validation
hook when encountering invalid field states.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON Form Issue / features related to the JSON form wiget ok-to-test Required label for CI Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Perf]: JSONForm re-rendering when field validation is configured
2 participants