Closed
Description
Describe the bug
<JsonForms/>
seems to do asynchronous onChange
, which breaks controlled style.
Expected behavior
onChange
is synchronous, thereby allowing use in controlled style.
Steps to reproduce the issue
Here is a very simple reproduction:
const schema = {
type: "object",
properties: {
value: {type: "number"},
},
};
function App() {
const [data, setData] = useState({value: 0});
useEffect(() => {
const interval = setInterval(() => {
// This is a stand-in for some external data change.
setData(data => ({...data}));
}, 10);
return () => clearInterval(interval);
}, []);
return (
<JsonForms
data={data}
renderers={vanillaRenderers}
cells={vanillaCells}
schema={schema}
onChange={({data}) => setData(data)}/>
);
}
https://codesandbox.io/p/sandbox/intelligent-snyder-y2p7m4?file=%2Fsrc%2FApp.tsx%3A18%2C10
You can easily see that data is being lost when rapidly typing a few digits into the input field.
Screenshots
No response
In which browser are you experiencing the issue?
Any
Which Version of JSON Forms are you using?
v3.1.0
Framework
React
RendererSet
Vanilla
I didn't test other RendererSets, but I assume they would have the same issue in React.
Additional context
It seems that the problem might be caused, at least in part, by the debounce in JsonFormsContext.tsx
, which, at first glance, seems to be fundamentally incompatible with controlled style.