question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validations run on unmount creating unnecessary requests

See original GitHub issue

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

When leaving a form that is embedded in a dialog, the form is unmounted which in turn calls unsubscribe and ultimately that runs field validations. In the case a user cancels on a complex form with server side validations, it creates a noticeable slowdown of ui as well as unnecessary requests to the server.

dashboard_-_archetype_com

What is the expected behavior?

Unmount will avoid unnecessary work.

Sandbox Link

Reproduction based on the Synchronous field-level validation https://codesandbox.io/s/pw19j1x52m

  1. allow to render initially
  2. clear console
  3. click Unmount form
  4. observe validations firing by added console logs

What’s your environment?

Sandbox updated to latest. ff: 4.11.0 rff: 4.0.2

Other information

possibly related #336

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
shrugscommented, Jul 31, 2019

I also ran into this bug, since we do cryptographic options to validate a form, when a form is unmounted (even post-submission), the unregistrations cause validation to run once for every field that was unmounted (including useField hooks that are only subscribing to state).

My solution is:

import { useEffect } from 'react';
import { useForm } from 'react-final-form';

/**
 * pauses validation when it becomes unmounted
 *
 * NOTE: this is useful because for some reason, final-form will
 * re-run validation when a field is unregistered (even post submission !?),
 * which react-final-form does on unmount. So when we redirect away from
 * a page with a form on it, all of the validation is re-triggered.
 *
 * Normally, for boring sync-validation-only situations, this is ok, but for
 * long-running validators like ours (deriving seeds, checking chain, etc)
 * having them re-triggered when a form leaves the page is hilariously bad.
 *
 * So here we disable validation when unmounting, saving ourselves
 * from the footgun.
 */
export default function ValidationPauser() {
  const form = useForm();

  useEffect(() => () => form.pauseValidation(), [form]);

  return null;
}

which should be placed as the first component within a Form’s children.

1reaction
erikrascommented, Nov 18, 2019

Published fix in v6.3.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Disable Required validation attribute under certain ...
You can remove all validation off a property with the following in your controller ... Create an attribute and mark your action method...
Read more >
Model validation in ASP.NET Core MVC | Microsoft Learn
Client-side validation prevents submission until the form is valid. The Submit button runs JavaScript that either submits the form or displays ...
Read more >
Form and field validation - Django documentation
A validator is a callable object or function that takes a value and returns nothing if the value is valid or raises a...
Read more >
Rails Validation: Pitfalls in Validating Uniqueness with Active ...
Rails provides an easy way to validate records for uniqueness, but relying solely on Rails validation could be quite troublesome.
Read more >
How to remove boilerplate validation logic in your REST APIs ...
Request validators also support basic validation of required HTTP ... To create the demo API, run the following commands (requires the AWS ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found