Skip to content

Add React and Redux DevTools#6793

Merged
whymarrh merged 3 commits intoMetaMask:developfrom
whymarrh:devtools2
Jul 11, 2019
Merged

Add React and Redux DevTools#6793
whymarrh merged 3 commits intoMetaMask:developfrom
whymarrh:devtools2

Conversation

@whymarrh
Copy link
Copy Markdown
Contributor

@whymarrh whymarrh commented Jul 3, 2019

Refs #5620 and #6455

This PR adds the React DevTools and Redux DevTools to the project. This allows us to more easily debug React components, their state and props, as well as the history of redux actions.

(New: there's now a single command, npm run start:dev that'll run these concurrently. See 19613ba for context. The following instructions also work.)

You can test this setup by:

$ npm start # And load the extension as you normally would

And in another terminal:

$ npm run devtools:react

> metamask-crx@0.0.0 devtools:react
> react-devtools

And in another terminal:

$ npm run devtools:redux

> metamask-crx@0.0.0 devtools:redux
> remotedev --hostname=localhost --port=8000

[RemoteDev] Start server...
--------------------------------------------------------------------------------

   [Busy] Launching SocketCluster
   [Active] SocketCluster started
            Version: 14.3.5
            Environment: dev
            WebSocket engine: ws
            Port: 8000
            Master PID: 23877
            Worker count: 1
            Broker count: 1

   [Done] Migrations are finished

Important pending tasks

  • Figure out how to make this not affect our bundle size (global.METAMASK_DEBUG is always falsy?)

Bundle size

Before After
npm start 44M 46M
npm run dist 3.6M 3.8M

Screenshots and videos

React DevTools:

Screen Shot 2019-07-03 at 17 41 25

Opening the Redux DevTools (first installing the extension):

Screen Shot 2019-07-03 at 17 23 08

Inspecting Redux state:

Screen Shot 2019-07-03 at 17 19 16

@whymarrh whymarrh requested a review from danjm as a code owner July 3, 2019 20:23
ui/index.js Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this should be behind some condition but I'm not sure what it is:

if (global.METAMASK_DEBUG) {
  require('react-devtools')
}

Here global.METAMASK_DEBUG is always falsy for some reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But maybe this doesn't matter as it's not a huge increase to our bundle?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it should be excluded from production builds. It's big enough.

Using METAMASK_DEBUG like you suggested seems perfectly fine to me. Another option would be adding it to the entries array in the gulpfile. Using a conditional is probably simpler though - easier to ensure it's only included in the ui bundle this way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah sorry, I missed the part about it being undefined. That's because it should be process.env.METAMASK_DEBUG.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I was confused by the use of global. a few lines below (which only works because it's after require('./app/store/store') which sets it 🤦‍♂

@whymarrh whymarrh requested a review from Gudahtt July 3, 2019 20:26
Gudahtt
Gudahtt previously approved these changes Jul 7, 2019
@danjm
Copy link
Copy Markdown
Contributor

danjm commented Jul 8, 2019

  • Can we easily update the gulp file to remove the additional bundle size
  • Documentation regarding workflow changes

@whymarrh whymarrh requested a review from Gudahtt July 8, 2019 15:23
@whymarrh
Copy link
Copy Markdown
Contributor Author

whymarrh commented Jul 8, 2019

I can confirm that this does still affect our bundle size. More detailed numbers:

Before After
npm run dist 3740918 (3.6M) 3937709 bytes (3.8M)

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Jul 8, 2019

I've just updated this branch to conditionally load devtools. It was a bit more challenging than I had expected - using require from Browserify didn't seem to work as I had hoped. I had to make a separate file to act as a second entrypoint for importing the dev tools.

@whymarrh
Copy link
Copy Markdown
Contributor Author

Documentation regarding workflow changes

I've updated the README with some new notes, see 19613ba

@whymarrh whymarrh merged commit 830c801 into MetaMask:develop Jul 11, 2019
@whymarrh whymarrh deleted the devtools2 branch July 11, 2019 14:57
@MarkOSullivan94
Copy link
Copy Markdown
Contributor

Delighted to see this merged! 🎉 Definitely will make it easier to inspect what is going on and debug 👍

Might be worthwhile adding to the documentation that for Redux Devtools to work, the checkbox Use custom (local) server has to be ticked.

Was trying to figure out why I couldn't see anything and then eventually figured out I had to tick that option in the settings 😅

Granted it was my first time using it, so perhaps that's why I wasn't sure what to do.

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Jul 17, 2019

We ran into the same problem! 😅
Definitely worth documenting that step, I agree.

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Jul 18, 2019

@MarkOSullivan94 I've just put up a PR to improve the documentation: #6882

Feel free to take a look, and let us know if it could be improved further! Thanks for the feedback.

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.

4 participants