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

(fix) O3-3858: Fix state update for registerContext #1121

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

kb019
Copy link
Contributor

@kb019 kb019 commented Aug 23, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

Summary

I had a use case for useDefineAppContext and useAppContext in ward app and for some weird reason useAppContext was not retriving updated valued provided in useDefineAppContext. By debugging i see that subscribe api was not called and i think subscribe api in zustand is only called when object has a new identity and not when the object is manipulated in place.
So i am changing the state update after testing in this in code sandbox.

In order to mimic the problem this pr solved just reset the state update to old one in codesandbox and press on refresh.(see console logs for values after and before resetting)

Screenshots

Related Issue

https://openmrs.atlassian.net/browse/O3-3858

Other

@kb019 kb019 changed the title Fix state update for registerContext (fix) O3-3858 : Fix state update for registerContext Aug 23, 2024
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! This is a result of initially writing this using Immer, which I then had to drop because the APIs didn't work as expected. Immer basically provides proxies so "modifying" the object results in the updated object as expected.

@ibacher ibacher merged commit 237bda7 into openmrs:main Aug 23, 2024
11 checks passed
@denniskigen denniskigen changed the title (fix) O3-3858 : Fix state update for registerContext (fix) O3-3858: Fix state update for registerContext Aug 23, 2024
@kb019
Copy link
Contributor Author

kb019 commented Aug 23, 2024

Nice catch! This is a result of initially writing this using Immer, which I then had to drop because the APIs didn't work as expected. Immer basically provides proxies so "modifying" the object results in the updated object as expected.

Thanks @ibacher , i now understand why it was like that. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants