-
Notifications
You must be signed in to change notification settings - Fork 376
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
Data loss when using React controlled style #2174
Comments
I'm happy to attempt a pull request if the underlying issue can be identified by someone with better knowledge of the codebase, since I don't fully understand the reasoning for adding the debounce in the first place. |
Hi @jwueller, I answered in more detail in the community thread. To summarize:
We would happily accept a contribution to improve the design. We're also working on other JSON Forms 4.0 changes so this would be a good fit for a release. |
Hi @sdirix 👋. We've recently started using JSON Forms (thank you for this lib BTW 🙇) and are hitting an issue where some of our UI Do you know if this is an issue that others have also encountered? |
In case it helps anyone else, I was able to mitigate this issue within our code by interleaving
is made reliable by changing to this:
where
|
We have a lot of UI tests too but we did not encounter these issues there. However we're still using enzyme, so some behavior might be different to
Thanks for posting this workaround which might help other developers. We also plan to switch testing frameworks in the "nearish" future, so we will definitely have a look at the issue then. |
Thanks for the update @sdirix 🙇. As for ourselves, we just encountered a more severe version of this race condition (that can't be mitigated with Perhaps we could help by offering a PR to move to the cleaner architecture that you describe? In my mind this would be as simple as:
I wasn't sure from your post whether you were thinking exactly the same however, since you didn't mention how you would switch between the controlled and uncontrolled modes, and whether this might even be done by having variations of the Thanks again, Dominic. |
Hi @dchambers, that would be amazing! I'll come back with more details next week. |
Hi @sdirix 👋, just a reminder that we're ready to start work on a PR once you're happy with the approach that we'll be taking. |
Hi @dchambers, sorry for the late reply.
This will not work. The A simple change is to offer
Conceptually this works, however it's not ideal for backward compatibility as it will break every user who did not update the A backward compatible change would be the introduction of the new data props and keeping the behavior of the current one. Or we allow to additionally configure a "mode" which is either "controlled", "uncontrolled" or "mixed" with "mixed" being the default. @lucas-koehler What do you think? |
Very nice 👍. A small additional tweak would be to only use This would be nice since:
Thoughts? |
Hi @dchambers, We discussed this issue internally and came to the following conclusions:
Does this make sense to you? Would you like to contribute this change? |
Hi @sdirix, Yes, this all makes sense, and we'd be very happy to contribute a PR for this change. One minor issue that we'd like to see plugged however is that, although it would be a backwardly compatible change for JS consumers, it would be a breaking change for TS consumers. Additionally, the TS code that fixed up the potentially incorrect type would be harder to write because it would be wanting to handle a type case that the developer was aware of, but the existence of which hadn't been admitted to the compiler. Instead, can we propose a very minor tweak to the plan as given. Assuming the following types: type GivenConfig = Config | DefaultUiSchemaOptions; // only used once at the input boundary
type Config = {
mode: 'controlled' | 'uncontrolled' | 'mixed';
defaultUiSchemaOptions: DefaultUiSchemaOptions;
};
type DefaultUiSchemaOptions = {
restrict: boolean;
trim: boolean;
showUnfocusedDescription: boolean;
hideRequiredAsterisk: boolean;
}; then:
With this small tweak:
Assuming that you're happy with this slight amendment we'll look to create a WiP PR for you to review in due course? |
Hi @dchambers, Sadly the suggestion is actually backward incompatible instead of just producing a typing issue. Not directly in the JSON Forms API, but within custom renderers. They will be broken as they expect the injected Regarding the suggested types: They look mostly fine, however almost all properties need to be optional. Also the Another point to think about: We already have a backward incompatible change in the works which will require a major version update. So we could combine this change with the other one for the release. In that case the suggested breakage of Of course we could also "deprecate" config or introduce another prop for the If you like you can definitely already start with the developing of the main feature (controlled mode) itself. The way we expose it at the end is not really important for now during development. |
Hi @sdirix, Thanks so much for your prompt reply. Everything you said makes perfect sense. Taking all of that into consideration, I believe that these updated types would work: type DefaultUiSchemaOptions = {
restrict?: boolean;
trim?: boolean;
showUnfocusedDescription?: boolean;
hideRequiredAsterisk?: boolean;
} & Record<string, unknown>;
type NonOptionConfig = {
mode: 'controlled' | 'uncontrolled' | 'mixed';
};
// the main `Config` type for use throughout the codebase
type Config = NonOptionConfig & {
defaultUiSchemaOptions: DefaultUiSchemaOptions;
};
// the type accepted at the input boundary so we remain backwardly compatible
type GivenConfig = Config | DefaultUiSchemaOptions;
// the type given to renderers, since requiring custom renderers to accept `Config` would be a breaking change
type RendererConfig = DefaultUiSchemaOptions & { nonOptionConfig: NonOptionConfig }; where We have started development BTW 😄, but feel free to holla if you think I've still got this wrong! |
This commit implements middleware support for both Angular and Vue, addressing the discussion in issue eclipsesource#2174
This commit implements middleware support for both Angular and Vue, addressing the discussion in issue eclipsesource#2174
This commit implements middleware support for both Angular and Vue, addressing the discussion in issue eclipsesource#2174
This commit implements middleware support for both Angular and Vue, addressing the discussion in issue eclipsesource#2174
Describe the bug
<JsonForms/>
seems to do asynchronousonChange
, 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:
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.The text was updated successfully, but these errors were encountered: