Repository: react-hook-form/react-hook-form
File: src/useForm.ts (TypeScript)

Code before:
        _f: {
          ...(isInitialRegister
            ? { ref: { name } }
            : {
                ref: (get(fieldsRef.current, name)._f || {}).ref,
                ...get(fieldsRef.current, name)._f,
              }),
          name,
          ...options,
        },
      });
      options && set(fieldsWithValidationRef.current, name, true);
      fieldsNamesRef.current.add(name);
      isInitialRegister && updateValidAndValue(name, options);

      return isWindowUndefined
        ? ({ name: name as InternalFieldName } as UseFormRegisterReturn)
        : {
            name,
            onChange: handleChange,
            onBlur: handleChange,
            ref: (ref: HTMLInputElement | null) =>
              ref
                ? registerFieldRef(name, ref, options)
                : shouldUnregister ||
                  (options && options.shouldUnregister && unregister(name)),
          };
    },
    [defaultValuesRef.current],
  );

  const handleSubmit: UseFormHandleSubmit<TFieldValues> = React.useCallback(
    (onValid, onInvalid) => async (e) => {
      if (e && e.preventDefault) {
        e.preventDefault();
        e.persist();
      }
      let fieldValues = {
        ...defaultValuesRef.current,
        ...getFieldsValues(fieldsRef, defaultValuesRef),
      };

      formStateSubjectRef.current.next({
        isSubmitting: true,
      });

      try {
        if (resolverRef.current) {
          const { errors, values } = await resolverRef.current(
            fieldValues,
            contextRef.current,

Review comment (suggestion):
If `shouldUnregister` is `true`, it won't call `unregister(name)` here.

```js
(shouldUnregister || options && options.shouldUnregister) && unregister(name),
```

Code after:
                ...get(fieldsRef.current, name)._f,
              }),
          name,
          ...options,
        },
      });
      options &&
        Object.keys(options).every((option) => option.indexOf('lu')) &&
        set(fieldsWithValidationRef.current, name, true);
      fieldsNamesRef.current.add(name);
      isInitialRegister && updateValidAndValue(name, options);

      return isWindowUndefined
        ? ({ name: name as InternalFieldName } as UseFormRegisterReturn)
        : {
            name,
            onChange: handleChange,
            onBlur: handleChange,
            ref: (ref: HTMLInputElement | null) =>
              ref
                ? registerFieldRef(name, ref, options)
                : (shouldUnregister || (options && options.shouldUnregister)) &&
                  unregister(name),
          };
    },
    [defaultValuesRef.current],
  );

  const handleSubmit: UseFormHandleSubmit<TFieldValues> = React.useCallback(
    (onValid, onInvalid) => async (e) => {
      if (e) {
        e.preventDefault && e.preventDefault();
        e.persist && e.persist();
      }
      let fieldValues = {
        ...defaultValuesRef.current,
        ...getFieldsValues(fieldsRef, defaultValuesRef),
      };

      formStateSubjectRef.current.next({
        isSubmitting: true,
      });

      try {
        if (resolverRef.current) {
          const { errors, values } = await resolverRef.current(
            fieldValues,
            contextRef.current,
            {
              criteriaMode,
              fields: getFields(fieldsNamesRef.current, fieldsRef.current),