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

Possible numericField bug (value lost when type of number changes) #46

Closed
Dretch opened this issue Dec 21, 2021 · 2 comments
Closed

Possible numericField bug (value lost when type of number changes) #46

Dretch opened this issue Dec 21, 2021 · 2 comments
Labels
bug Something isn't working correctly

Comments

@Dretch
Copy link
Contributor

Dretch commented Dec 21, 2021

Hello, this library has a really nice design and docs, so thanks!

I have found what might be a bug (possibly I just misunderstand how things should be working, though).

I have a numericFieldV that stays in the same position in the widget tree, but sometimes contains an Integer value and other times contains a Float. The value is preserved as much as possible (using truncate/fromIntegral) when switching between the types.

I expected the value to stay showing (just changing whether it has a fractional part or not) when the type changes, but instead the numeric field loses the value and goes back to empty. This is demonstrated by this modification of the helloworld example: monomer-numeric-field-issue.zip

@Dretch Dretch changed the title Possible numericField bug Possible numericField bug (value lost when type of number changes) Dec 21, 2021
@fjvallarino
Copy link
Owner

Hi @Dretch!

I honestly hadn't considered this use case, and the reason it fails is because the internal state types do not match. When the user model changes, each widget is merged with the corresponding widget in the previous version of the tree. The old version of each widget is chosen based on position or nodeKey, also validating that their WidgetType matches (otherwise, the internal state types of the widgets would not match). Up to now, numericField set its WidgetType to numericField, which usually works fine but, when the type of the handled value changes, the internal types do not match anymore and merge does not run (in your case, switching from Double to Int).

This branch's version appends the handled type to the WidgetKey, so numericField will set itself to numericField-Double or numericField-Int. This is all internal, and you don't need to change anything.

To test this change, you can modify your stack.yaml to use this specific commit:

- git: https://github.com/fjvallarino/monomer.git
  commit: ce9e660a1b7f5ede6df1576686b362aefe7927e8

Let me know if this works as expected!

Ideally, I will release a new version by the end of the year, including this change and a few other things I have pending.

@Dretch
Copy link
Contributor Author

Dretch commented Dec 22, 2021

Thanks for the explanation and the fix @fjvallarino (that works great) 🥇

@Dretch Dretch closed this as completed Dec 22, 2021
@fjvallarino fjvallarino added the bug Something isn't working correctly label Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

2 participants