Skip to content

useForm's initializing and useField's formInitializing do not agree with each other on load #9263

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

Closed
tyteen4a03 opened this issue Nov 17, 2024 · 3 comments

Comments

@tyteen4a03
Copy link
Contributor

Describe the Bug

I don't know if this is a bug or intentional behavior, but useForm()'s initializing and useField's formInitializing do not agree with each other when the form is being loaded. This component highlights this behavior:

const TestClientField: UIFieldClientComponent = ()  => {
  const { initializing } = useForm();
  const { formInitializing } = useField({
    path: '',
  });

  if (initializing !== formInitializing) {
    console.log("initializing != formInitializing!", initializing, formInitializing);
  } else {
    console.log("initializing == formInitializing", initializing, formInitializing);
  }

  return <>test</>
}

Link to the code that reproduces this issue

https://github.com/tyteen4a03/payload-forminitializing-bug

Reproduction Steps

  1. Run the repro repo.
  2. Navigate to the Media collection
  3. Open the Console, then refresh the page.
  4. See the warning in the console: initializing != formInitializing! false true

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Node.js v22.11.0

Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.13.0
Relevant Packages:
  payload: 3.0.0-beta.133
  next: 15.0.0
  @payloadcms/db-mongodb: 3.0.0-beta.133
  @payloadcms/email-nodemailer: 3.0.0-beta.133
  @payloadcms/graphql: 3.0.0-beta.133
  @payloadcms/next/utilities: 3.0.0-beta.133
  @payloadcms/payload-cloud: 3.0.0-beta.133
  @payloadcms/richtext-lexical: 3.0.0-beta.133
  @payloadcms/translations: 3.0.0-beta.133
  @payloadcms/ui/shared: 3.0.0-beta.133
  react: 19.0.0-rc-65a56d0e-20241020
  react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
@tyteen4a03 tyteen4a03 added status: needs-triage Possible bug which hasn't been reproduced yet v3 validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels Nov 17, 2024
@github-actions github-actions bot added created-by: Contributor and removed validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels Nov 17, 2024
@denolfe denolfe removed the v3 label Nov 19, 2024
@jessrynkar jessrynkar self-assigned this May 8, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label May 8, 2025
@jessrynkar
Copy link
Member

Hi @tyteen4a03 - I initially thought this was a bug also, but after digging a little deeper I found:

useForm().initializing finishes when the form’s global state is ready
useField().formInitializing waits for the form state to be ready and the field to finish its own setup (like permissions, conditional logic, etc.)

That’s why initializing from useForm() turns to false sooner — it doesn’t wait for all the extra field-level processes. Each field might still be setting itself up even after the form is technically initialized.

This isn't super intuitive but is expected behavior. Thanks for raising this and I hope this helps to clear things up.

@tyteen4a03
Copy link
Contributor Author

Can this be documented in the docs? If you have client sided code for one field that interacts with another field, this behavior is problematic.

Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants