openmrs / openmrs-esm-form-engine-lib

React Form Engine library for O3
Other
10 stars 59 forks source link

(fix) Propagate Form Context State Changes to the Form Factory Provider #402

Closed samuelmale closed 2 weeks ago

samuelmale commented 2 weeks ago

Requirements

Summary

During initialization, the form renderer registers the associated form context with the form-factory provider, which can be either a root form or a subform. This context is stored as an object reference in memory. As the user interacts with the form, the context undergoes mutations as a side-effect. In most cases, these mutations do not cause issues because they occur at deeper levels within the object tree, and most state updates perform shallow clones. However, problems arise when state mutations happen at higher levels, such as with the formFields state.

This has caused to a bug with repeating fields, where newly cloned fields do not exist in the factory provider during submission.


This fix ensures that state updates are properly propagated, addressing the issue and maintaining consistency across the form context.

Screenshots

N/A

Related Issue

N/A

Other

samuelmale commented 2 weeks ago

@CynthiaKamau this fixes the issue you reported earlier today about test orders.

github-actions[bot] commented 2 weeks ago

Size Change: -4 B (0%)

Total Size: 1.15 MB

ℹ️ View Unchanged | Filename | Size | Change | | :--- | :---: | :---: | | `dist/151.js` | 300 kB | 0 B | | `dist/225.js` | 2.57 kB | 0 B | | `dist/277.js` | 1.84 kB | 0 B | | `dist/300.js` | 642 B | 0 B | | `dist/335.js` | 968 B | 0 B | | `dist/353.js` | 3.02 kB | 0 B | | `dist/41.js` | 3.37 kB | 0 B | | `dist/422.js` | 6.8 kB | 0 B | | `dist/501.js` | 108 kB | 0 B | | `dist/540.js` | 2.63 kB | 0 B | | `dist/55.js` | 758 B | 0 B | | `dist/572.js` | 252 kB | -4 B (0%) | | `dist/617.js` | 86.9 kB | 0 B | | `dist/635.js` | 14.3 kB | 0 B | | `dist/70.js` | 483 B | 0 B | | `dist/901.js` | 11.8 kB | 0 B | | `dist/99.js` | 691 B | 0 B | | `dist/993.js` | 3.09 kB | 0 B | | `dist/main.js` | 342 kB | 0 B | | `dist/openmrs-esm-form-engine-lib.js` | 3.67 kB | 0 B |

compressed-size-action

CynthiaKamau commented 2 weeks ago

@samuelmale , try testing this out on edit mode , it looks like the field values are not populated

samuelmale commented 2 weeks ago

does this change fix propagating the changes downstream as well?

No, it's not related to that.

try testing this out on edit mode , it looks like the field values are not populated

I just tested it out and it works as expected for me. @CynthiaKamau Can you provide more details?