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

feat: add integration with Redux DevTools #289

Merged
merged 6 commits into from
Sep 6, 2023

Conversation

pac-guerreiro
Copy link
Contributor

Details

This PR adds the ability to use React Native Onyx with Redux DevTools to debug storage changes.

Features:

  • View SET, MULTISET, MERGE, REMOVE and CLEAR actions in DevTools: payload data corresponds to the data which was written into the storage;

  • View state diffs when an action is selected;

  • View current state at the time an action was called;

  • Time travelling is not possible (yet)

Related Issues

None

Automated Tests

Not needed because this doesn't affect internal behaviour

Linked PRs

None

@pac-guerreiro pac-guerreiro requested a review from a team as a code owner July 27, 2023 09:53
@github-actions
Copy link
Contributor

github-actions bot commented Jul 27, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@melvin-bot melvin-bot bot requested review from Gonals and removed request for a team July 27, 2023 09:53
@pac-guerreiro
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@AndrewGable
Copy link
Contributor

Can you please add some documentation on how to get this setup as a developer?

@pac-guerreiro pac-guerreiro force-pushed the feature/remotedev branch 2 times, most recently from 698a175 to c63c063 Compare July 28, 2023 16:46
@pac-guerreiro
Copy link
Contributor Author

@AndrewGable

I just added some instructions to the README.md and also updated the API.md.

I decided to differentiate between debugging setState and using Redux DevTools extension.

Let me know what you think! 😄

@Gonals Gonals requested a review from a team July 31, 2023 09:31
@melvin-bot melvin-bot bot requested review from PauloGasparSv and removed request for a team July 31, 2023 09:32
@PauloGasparSv
Copy link

Hey @pac-guerreiro we have a conflict now, can you please take a look?

I'll review this tomorrow, got back from OOO today and had to prioritize other issues/reviews.


First, install Redux DevTools through your favorite browser ([Edge](https://microsoftedge.microsoft.com/addons/detail/redux-devtools/nnkgneoiohoecpdiaponcejilbhhikei), [Chrome](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd), [Firefox](https://addons.mozilla.org/en-US/firefox/addon/reduxdevtools/))

Then, you can enable this type of debugging by passing `enableDevTools: true` to `Onyx.init({...})`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda wonder if this should be enabled by default on dev?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndrewGable I'm not sure if it won't be impactful on performance 😅

@pac-guerreiro
Copy link
Contributor Author

Hey @pac-guerreiro we have a conflict now, can you please take a look?

I'll review this tomorrow, got back from OOO today and had to prioritize other issues/reviews.

@PauloGasparSv I just resolved the conflict 😄

@PauloGasparSv
Copy link

Sorry for the delay, I had time to check the changes here (so far lgtm) but didn't test this yet. Will test it using the extension tomorrow : )

@pac-guerreiro
Copy link
Contributor Author

@PauloGasparSv

No problem 😄 I just fixed the tests that were broken because of my changes!

lib/DevTools.js Outdated
@@ -0,0 +1,54 @@
import {connectViaExtension, extractState} from 'remotedev';
Copy link

@PauloGasparSv PauloGasparSv Aug 3, 2023

Choose a reason for hiding this comment

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

Hey @pac-guerreiro I'm really curious on how you decided on using remotedev! I'm relatively new to React/ReactNative so would love to know : D

I could only find this slack post you sent recently on this.

(btw, this is super cool)
(btw 2, had to shift focus but I'm still planning on testing today)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PauloGasparSv

Sorry for the late response, I'm glad you like this idea 😄 I hope it helps a lot of developers working on the app 😄

Well, at first I thought I could fork the repo for redux dev tools extension but then I found it was too complex to adapt it as it was for Onyx, so after some digging and research I found remotedev, which was made by the same guy behind redux dev tools extension, if I'm not mistaken. It basically provides an api to connect to redux dev tools or any other extension that supports remotedev, so I gave it a shot and it worked 😄

PauloGasparSv
PauloGasparSv previously approved these changes Aug 7, 2023
Copy link

@PauloGasparSv PauloGasparSv left a comment

Choose a reason for hiding this comment

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

LGTM, this is pretty neat!

image

All yours @AndrewGable @Gonals

@Gonals Gonals removed their request for review August 8, 2023 13:17
@Gonals
Copy link
Contributor

Gonals commented Aug 8, 2023

OOO starting tomorrow, so removing myself!

@PauloGasparSv
Copy link

@pac-guerreiro do you mind fixing the new conflicts we have?

Bump @AndrewGable for a review : D

AndrewGable
AndrewGable previously approved these changes Aug 8, 2023
@pac-guerreiro
Copy link
Contributor Author

@PauloGasparSv

It is done 😄

@PauloGasparSv
Copy link

PauloGasparSv commented Aug 9, 2023

Hey @pac-guerreiro I think I may have found a bug in this line this time (didn't happen before, not sure why it happened this time):

image

I think the initial state can be undefined:

image

I think this error prevented me from signing because after I reinstalled dependencies the error was gone and I could sign in as usual.

Can you please take a look at that?
LMK if you can't replicate, maybe there is a problem in my environment :D

@pac-guerreiro
Copy link
Contributor Author

@PauloGasparSv

This issue happens inside remotedev's extractState function, in which JSON.parse returns this state as undefined sometimes 😅

Honestly, I guess the whole callback passed to DevTools constructor can be discarded since this was meant to update the storage each time we time travel between actions in DevTools but it doesn't work correctly 😅

@PauloGasparSv
Copy link

This issue happens inside remotedev's extractState function, in which JSON.parse returns this state as undefined sometimes 😅

Oh I see, I didn't double check but does it return undefined even if there is state data there?

If that's the case then it doesn't even make sense to coalesce that value but maybe we can skip that logic that removes the keys in case newState is undefined

Honestly, I guess the whole callback passed to DevTools constructor can be discarded since this was meant to update the storage each time we time travel between actions in DevTools but it doesn't work correctly 😅

Really?? So we don't that need that bit of logic?

Sorry for the confusion ahaha I'm trying to understand what we can do next here : )

@pac-guerreiro
Copy link
Contributor Author

@PauloGasparSv

Oh I see, I didn't double check but does it return undefined even if there is state data there?

Yeah, I think it has some trouble parsing slash tokens sometimes, maybe because the extension is sending some messages in a format that remotedev is not ready to interpret 😅

Really?? So we don't that need that bit of logic?

It could be useful for debugging purposes if a dev wants to go back in time and see the state changes in real-time, but since this logic is broken because either that undefined issue occurs or it does work but going back causes new events to get triggered and shown in the dev tools 😅

So yeah, if you think it's better, I can drop this logic and we just provide the ability to check state changes in real time 😄

@PauloGasparSv
Copy link

So yeah, if you think it's better, I can drop this logic and we just provide the ability to check state changes in real time 😄

That sounds awesome to me! @AndrewGable do you mind giving your opinion on this too?

@PauloGasparSv
Copy link

Bump @AndrewGable : )

@AndrewGable
Copy link
Contributor

Yes that sounds good 👍

@PauloGasparSv
Copy link

Bump @pac-guerreiro :D

@TomaszFrackowiak
Copy link

@PauloGasparSv - hey, just to let you know that @pac-guerreiro is ooo till 25.08

@PauloGasparSv
Copy link

@PauloGasparSv - hey, just to let you know that @pac-guerreiro is ooo till 25.08

Wasn't aware, thanks a lot @TomaszFrackowiak!!!

@pac-guerreiro
Copy link
Contributor Author

@PauloGasparSv

Sorry for not warning you about my vacation!

I just removed the code that was causing problems and resolved conflicts 😄

@pac-guerreiro
Copy link
Contributor Author

Bump @AndrewGable

@AndrewGable
Copy link
Contributor

Screenshot 2023-09-05 at 1 49 46 PM

Oops. Looks like your going to have to re-sign your commits.

Pedro Guerreiro and others added 6 commits September 6, 2023 19:57
@pac-guerreiro
Copy link
Contributor Author

@AndrewGable it is solved now 😄

@AndrewGable AndrewGable merged commit 35ef09a into Expensify:main Sep 6, 2023
3 checks passed
@ospfranco
Copy link
Contributor

Trying to run the tests on the main Expensify repo and this change causes the tests to fail:

CleanShot 2023-09-11 at 10 40 38

Seems the remotedev dependency was added as a dev dependency which is not installed when ran from the main repo.

mountiny added a commit that referenced this pull request Sep 12, 2023
Revert "Merge pull request #289 from pac-guerreiro/feature/remotedev"
@AndrewGable
Copy link
Contributor

@pac-guerreiro - Can you address this issue in a PR then re-submit? Looks like this PR was reverted.

@pac-guerreiro
Copy link
Contributor Author

@AndrewGable Hope I'm not late to the party but here's the new PR for this work - #438

I redone everything from scratch since some things got changed in Onyx during this period.

Instead of relying on third party node modules, I decided to implement the logic to connect to the extension by myself after doing some research into remotedev repo.

Onyx will connect to Redux DevTools extension by default.

Developers will only be able to use this functionality on web apps.

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.

6 participants