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

[Bug] Todo - Move First to End - Warning: Cannot update a component (ForwardRef) while rendering a different component (Field) #193

Open
awhitford opened this issue Mar 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@awhitford
Copy link

Steps to Reproduce

  1. Run the React Playground
  2. Open the Chrome Developer Tools to see the JavaScript Console
  3. Choose the Todos tab
  4. Click Move first to end

Check the JavaScript Console and you will see an error like:

react-dom_client.js?v=d064dc83:521 Warning: Cannot update a component (`ForwardRef`) while rendering a different component (`Field`). To locate the bad setState() call inside `Field`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
    at Field (http://localhost:5173/@fs/Users/anthony/github/awhitford/modular-forms/packages/react/dist/index.mjs:91:27)
    at div
    at div
    at div
    at div
    at FieldArray (http://localhost:5173/@fs/Users/anthony/github/awhitford/modular-forms/packages/react/dist/index.mjs:92:32)
    at div
    at form
    at Form
    at TodosPage (http://localhost:5173/src/routes/todos.tsx:35:8)
    at RenderedRoute (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=d064dc83:3265:5)
    at Routes (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=d064dc83:3718:5)
    at main
    at Router (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=d064dc83:3665:15)
    at BrowserRouter (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=d064dc83:4132:5)
    at App
@fabian-hiller fabian-hiller self-assigned this Mar 12, 2024
@fabian-hiller fabian-hiller added the bug Something isn't working label Mar 12, 2024
@fabian-hiller
Copy link
Owner

Thank you for creating this issue! Do you know how to fix it?

@awhitford
Copy link
Author

I can't quite figure it out. Looks like the Field: (props) => Field({ ...props, of: form }), line:

function useForm(options) {
  const form = useFormStore(options);
  return useMemo(
    () => [
      form,
      {
        Form: (props) => Form({ ...props, of: form }),
        Field: (props) => Field({ ...props, of: form }),
        FieldArray: (props) => FieldArray({ ...props, of: form })
      }
    ],
    [form]
  );
}

And they reference this Bug: too hard to fix "Cannot update a component from inside the function body of a different component.". I tried upgrading to the latest dependencies thinking that maybe it would solve it or perhaps give a better error message, but doesn't change the issue.

@fabian-hiller
Copy link
Owner

I am currently focused on Valibot and also plan to rewrite Modular Forms later this year. That's why I'm not spending that much time on the current code of the library. Sorry for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants