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/reduce bundle size #106

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

icyJoseph
Copy link
Contributor

@icyJoseph icyJoseph commented Jul 7, 2020

This PR tries to implement #55 :)

It introduces a bunch of refactoring of Routes, removes React-Markdown, applies React features such as lazy loading + Suspense and Webpack dynamic imports.

Today navigating to an invalid Route, renders a table with a bunch of zeroes. This takes care of it.

I know one should squash commits, we can do that, but would be nice to discuss the PR first. The commits list helps follow how the feature evolved.

I also needed to merge master, we should make sure things are alright.

image

Cheers!

@codecov
Copy link

codecov bot commented Jul 7, 2020

Codecov Report

Merging #106 into master will increase coverage by 1.80%.
The diff coverage is 85.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #106      +/-   ##
==========================================
+ Coverage   76.80%   78.61%   +1.80%     
==========================================
  Files          55       38      -17     
  Lines        1341     1230     -111     
  Branches      155      141      -14     
==========================================
- Hits         1030      967      -63     
+ Misses        275      235      -40     
+ Partials       36       28       -8     
Impacted Files Coverage Δ
src/components/generic/SmallWidgets.js 90.00% <ø> (ø)
src/components/pages/WalkingGaitsPage.js 0.00% <0.00%> (-9.84%) ⬇️
src/components/pages/InverseKinematicsPage.js 59.25% <16.66%> (+3.70%) ⬆️
src/components/DimensionsWidget.js 67.85% <33.33%> (+1.19%) ⬆️
src/components/pages/LegPatternPage.js 57.89% <33.33%> (ø)
src/components/pages/ForwardKinematicsPage.js 74.07% <50.00%> (+0.99%) ⬆️
src/components/hooks/useHexapodParams.js 84.61% <84.61%> (ø)
src/components/hooks/usePlot.js 84.61% <84.61%> (ø)
src/loadables.js 88.00% <88.00%> (ø)
src/App.js 100.00% <100.00%> (+14.28%) ⬆️
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f02fd4d...a51f61f. Read the comment docs.

@icyJoseph
Copy link
Contributor Author

I had done a bad glob pattern, but a later commit fixes it.

@mithi
Copy link
Owner

mithi commented Jul 7, 2020

For comparison

Before

Screen Shot 2020-07-07 at 6 30 11 PM

After

Screen Shot 2020-07-07 at 6 28 41 PM

|


export default () => (
<div className="no-match">
<h1>404</h1>
Copy link
Owner

Choose a reason for hiding this comment

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

Really cool 404 page 😊

@@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/react": "^10.4.4",
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for bumping this up 👍 💯

@mithi
Copy link
Owner

mithi commented Jul 7, 2020

@icyJoseph

The problem I have with this is that, I notice that ever time I switch back and forth from the landing page to a page with a plot, it reloads the plot (for a second or two).

The current behavior:

At the beginning (when you visit the site), it takes a while to load, but once it is loaded, whenever you switch to any page, there is no wait time.

This new behavior:

Switching between any page with a plot is extremely fast, but if I accidentally visit the landing page again, I have to reload the plot again. I think it shouldn't have to reload the plot again...

What do you think?

src/App.js Outdated
@@ -115,34 +116,26 @@ class App extends React.Component {
* * * * * * * * * * * * * */

render() {
const { plot, ...rest } = this.state
const routeProps = {
Copy link
Owner

Choose a reason for hiding this comment

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

Could there be a better way to structure this than pushing about 15 props on route?

Maybe using contexts ?

Copy link
Contributor Author

@icyJoseph icyJoseph Jul 7, 2020

Choose a reason for hiding this comment

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

Yes, I actually a branch where I've built the Provider pattern, so that'll come up next.

I just needed to understand correctly which pieces of state are running through the App. For instance in that branch I have it divided as hexapod params, plot data, and the rest of settings. And that results in 3 context providers.

Edit
Forgot to say here that the main reason I did this strange props arrangement was to keep the render method under 25 lines and pass the code checks.

@icyJoseph
Copy link
Contributor Author

icyJoseph commented Jul 7, 2020

@icyJoseph

The problem I have with this is that, I notice that ever time I switch back and forth from the landing page to a page with a plot, it reloads the plot (for a second or two).

The current behavior:

At the beginning (when you visit the site), it takes a while to load, but once it is loaded, whenever you switch to any page, there is no wait time.

This new behavior:

Switching between any page with a plot is extremely fast, but if I accidentally visit the landing page again, I have to reload the plot again. I think it shouldn't have to reload the plot again...

What do you think?

@mithi

With all the changes now done, I started to use the HTML attribute hidden, which is the pretty much the same as using display: none, with has full browser support.

Now the site will load fast, and in the background it'll be downloading and rendering the HexapodPlot page, if the user clicks too fast on a route, they might catch the Loading state. Once loaded, you can go to the Root, back and forth and there won't be reloading of the Plot.

See how it works now :D


const Nav = () => <NavBullets />
const Nav = React.memo(() => <NavBullets />)
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for using React.memo in Nav 😄

@mithi
Copy link
Owner

mithi commented Jul 7, 2020

See how it works now :D

Great! Do you think the plot should also be hidden in the 404 page?

I'm thinking about using profiler to measure the performance gains of your changes 😃
https://reactjs.org/docs/optimizing-performance.html#profiling-components-with-the-chrome-performance-tab

@icyJoseph
Copy link
Contributor Author

There should be some gains. Here's an article I wrote somw time ago about using these tricks :)

I am actually not sure about what the 404 page should show. Up to you ^^

@icyJoseph
Copy link
Contributor Author

icyJoseph commented Jul 7, 2020

Found and fixed a bug. Needed to update updateIkParams and updatePatternPose to updateIk and updatePose.

@mithi
Copy link
Owner

mithi commented Jul 7, 2020

@icyJoseph

There should be some gains. Here's an article I wrote some time ago about using these tricks :)

Thanks for sharing! I'll read it! (And also your other articles)

Instead of displaying a 404 page, shouldn't we just redirect to the landing page?

Also, just a heads-up I'm implementing a walking gait page
( https://github.com/mithi/hexapod/tree/add-walking )

Also, I'm moving AlertBox and PoseTable inside the InverseKinematicsPage (as it should have had been from the very start! ) That means I'm removing some things in the App's state, simplifying the App component. 😃

@icyJoseph
Copy link
Contributor Author

@mithi

Instead of displaying a 404 page, shouldn't we just redirect to the landing page?

Alright, I think it should be fine in this case.

Also, just a heads-up I'm implementing a walking gait page
( https://github.com/mithi/hexapod/tree/add-walking )

Oh that sound amazing 😮

Also, I'm moving AlertBox and PoseTable inside the InverseKinematicsPage (as it should have had been from the very start! ) That means I'm removing some things in the App's state, simplifying the App component.

Sweet! less global state is always welcomed

@icyJoseph
Copy link
Contributor Author

I have not added the 404 Redirect back to room and merged master into this branch. Please do check that the Walking Gait is working as expected 😄

Gonna try to fix the issues throughout the day.

@icyJoseph
Copy link
Contributor Author

Had to use the hooks -> render props -> HoCs pattern architecture to remove about 7 code climate issues, now there's only two regarding params injected to some of the routes. I might fix it today.

The walking animations looks AMAZING! 🎉

@mithi
Copy link
Owner

mithi commented Jul 8, 2020

I might fix it today.

Please do take your time and do not rush or hurry. Thanks for all your time, effort and all your hard work!
I will also study how to use the profiler to measure the performance gains of your changes. It will take me a bit of time.

src/App.js Outdated
<Routes {...routeProps} onPageLoad={this.onPageLoad} />
</Route>
<Route>
<Redirect to="/" />
Copy link
Owner

Choose a reason for hiding this comment

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

💯 👍

@icyJoseph
Copy link
Contributor Author

Ah :D I think this PR is ready for some serious merging considerations 💯

@mithi mithi linked an issue Jul 8, 2020 that may be closed by this pull request
4 tasks
@mithi mithi mentioned this pull request Jul 22, 2020
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.

Optimize: Reduce Bundle Size Further
2 participants