I'm trying to drop preact/compat into a large React app (with SSR) - and this is the final blocker for me.
library in question:
description of problem:
Things such as 'initialValues' just dont work (see the codesandbox), which is the easiest to reproduce, but just in general there seems to be 'internal state problems' with informed+preact
codesandbox example of initialValues not taking effect
If you immediately submit that form - you'll see the object logged to the console is missing the initially set value.
Many thanks for reviewing :)
https://github.com/joepuzzo/informed/issues/247 might be related.
I did some debugging and it seems like React is going through rendering phase twice before committing, and running effects on 2nd rendering phase. At the 2nd run, at this hook it sets values to the Form state.
The difference with Preact is that it's running that hook callback on the 1st component execution, but values are present after that, on component re-render - set with useState hook.
Sorry should've already linked this here: https://preact.slack.com/archives/C3NMBSJKH/p1569162715058400?thread_ts=1569142082.049000&cid=C3NMBSJKH
I have researched this but gave the response in slack, this code is subject to fail in React concurrent mode due to batching. Preact batches by default.
The clean solution for informed would be to set the initialValues to values at construction instead of relying on two sources of truth.
Most helpful comment
Sorry should've already linked this here: https://preact.slack.com/archives/C3NMBSJKH/p1569162715058400?thread_ts=1569142082.049000&cid=C3NMBSJKH
I have researched this but gave the response in slack, this code is subject to fail in React concurrent mode due to batching. Preact batches by default.
The clean solution for informed would be to set the initialValues to values at construction instead of relying on two sources of truth.