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

Show both internal and shared state managment in example. #7312

Merged
merged 13 commits into from
May 23, 2019

Conversation

scull7
Copy link
Contributor

@scull7 scull7 commented May 12, 2019

I pointed someone at this example and they were confused by the
shared state example. To help with their confusion I updated
the example to show both shared and internal component state
management.

I've changed the GlobalCount implementation to internally use a reducer hook and expose it as a custom hook. This keeps all of the global state tracking locked into the GlobalCount module and the Counter component just uses the custom hook as it would any other reducer hook.

I think this presents a clean pattern that doesn't introduce very many new concepts. As a bonus this fixes the duplicate increment on first click after load issue.

I pointed someone at this example and they were confused by the
shared state example.  To help with their confusion I updated
the example to show both shared and internal component state.

There is an issue with the `IncrementGlobal` action that I've so
far been unable to sort out.  Upon first load, if you click the `Add`
button beneath the `Persistan Count` display then the `IncrementGlobal`
action seems to be dispatched twice on a single click.  Hopefully,
someone will be able to point out my, likely, very dumb error.
@scull7 scull7 requested a review from lfades as a code owner May 12, 2019 09:00
@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.7s 15.5s -198ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB -1 B
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.11 kB -1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB -1 B
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 16.5s 17.1s ⚠️ +586ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB ⚠️ +1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB ⚠️ +1 B
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB ⚠️ +1 B
Build Dir Size 2.37 MB 2.37 MB

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 14.6s 14.4s -228ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.11 kB 3.11 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 16.2s 16.1s -97ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB -1 B
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.11 kB -1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB -1 B
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB -3 B
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -3 B
Build Dir Size 2.37 MB 2.37 MB

@arecvlohe
Copy link

It might be worth using the context api since the new reason-react supports it.

@scull7
Copy link
Contributor Author

scull7 commented May 12, 2019 via email

@arecvlohe
Copy link

arecvlohe commented May 12, 2019

There are a few domain specific configurations for Next.js. Based on the redux example it looks as though you can create a _app.js the acts as a wrapper for your page components: https://github.com/zeit/next.js/blob/master/examples/with-redux/pages/_app.js. In this case, you would create your context in reason and then import it into your _app.js file and pass it down using react context API.

@scull7
Copy link
Contributor Author

scull7 commented May 12, 2019 via email

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.6s 15.6s -54ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 17.4s 17.4s ⚠️ +33ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB -2 B
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB ⚠️ +2 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -1 B
Build Dir Size 2.37 MB 2.37 MB

Adding a custom hook to track the global state eliminates the
double increment on first click issue and leads to all of the
reference tracking being in the GlobalCount module.

Also, this does not require the use of any odd concept within
the components themselves.
@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 13.6s 14s ⚠️ +373ms
node_modules Size 40 MB 40 MB -62 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB ⚠️ +1 B
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.11 kB 3.12 kB ⚠️ +1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB ⚠️ +1 B
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.7s 15.5s -199ms
node_modules Size 40 MB 40 MB -62 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB -1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB ⚠️ +3 B
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB
Build Dir Size 2.37 MB 2.37 MB

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.2s 15.2s ⚠️ +50ms
node_modules Size 40 MB 40 MB -62 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 16.7s 16.7s ⚠️ +52ms
node_modules Size 40 MB 40 MB -62 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB -2 B
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB -1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -1 B
Build Dir Size 2.37 MB 2.37 MB

@scull7
Copy link
Contributor Author

scull7 commented May 15, 2019

@arecvlohe I've updated the implementation to use a custom hook. I muddled around with using the Context API but found that it was very confusing to me and required me to mix in a lot of JavaScript.

Benefits of the custom hook implementation

  1. All concerns are separated nicely
  2. No new raw JavaScript code was required.
  3. Duplicate increment issue on first click after load was solved.

Let me know what you think.

@arecvlohe
Copy link

@scull7 Let me play around with this tomorrow and get back to you. I think there is a nice way to work with context that doesn't require interop with JS. I kinda want to exhaust this possibility first. There is a nice example of context that I found in the discord channel so I will use that for inspiration.

@scull7
Copy link
Contributor Author

scull7 commented May 15, 2019

Why the desire to use the context API? The idea of it seems to run counter to one of the benefits of the hooks API. Namely removing extraneous wrapping from the DOM structure.

The more I consider the global state reducer implementation; is this not what redux (and the Elm architecture) are doing implicitly?

@arecvlohe
Copy link

Well, I would like to explore this option. I am not necessarily tied to it. Just want to see what's possible. At the end of the day this is your PR so you can push it forward without any of my input but it would be nice to see if the API can be improved in any way.

@scull7
Copy link
Contributor Author

scull7 commented May 15, 2019 via email

@arecvlohe
Copy link

It's all good! I understand why you have some reservation about using context API since it might add more complexity than is necessary. My reservation is using a mutable reference as a means to hold state. You can say I am a bit of a purist in those regards. I am working on using the context API now and I should have something ready pretty soon. We can mull it over and see what makes the most sense. But this is still your PR so you can decide whether it's valuable or not.

@scull7
Copy link
Contributor Author

scull7 commented May 15, 2019

I look forward to seeing what you come up with. I understand the purity argument. But I think of the reference in this case as similar to using something like local storage, which for an example might cloud the purpose. Although, someone might also think that this is a good way to store state and that would probably not be good also... so 🤷‍♂

Also, while I generated the PR, I think this should be something more than just me thinks is a good idea.

@arecvlohe
Copy link

@scull7 I have a commit I would like to push to your branch. It's just 1 commit so you could easily remove it by rebasing. I just need permission to push to your branch and I can push up my changes.

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 13.9s 13.5s -361ms
node_modules Size 40 MB 40 MB ⚠️ +37 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15s 14.8s -114ms
node_modules Size 40 MB 40 MB ⚠️ +37 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB -1 B
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.11 kB -1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB -1 B
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB ⚠️ +1 B
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -2 B
Build Dir Size 2.37 MB 2.37 MB

Copy link
Contributor Author

@scull7 scull7 left a comment

Choose a reason for hiding this comment

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

I think this would be better served as a separate example because it adds quite a bit of complexity. But I'm not an expert by any means.

const { Component, pageProps, store } = this.props
return (
<Container>
<CountProvider>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like this wrapping is exactly what the Hooks API is trying to avoid. Is there another way we can inject the provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, we're injecting context in a place where it takes quite a leap to find.

Choose a reason for hiding this comment

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

I don't think there is another way to inject the provider if we want it to work on every page without having to prepend it to the top level of index.re and about.re. I see this as a constraint of next being a JS framework and so have to work with its nuance.

As far as wrapping and how it relates to hooks, you still need a Provider, so I don't think there is a way to get around wrapping in terms of the context API. Maybe in the new version of reductive this will be solved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like a lot of ceremony to avoid the use of a ref. I think the ref can be avoided if your willing to simply replace the state on each update.

Also, now we are introducing many more concepts, steps and indirections.

I get that you may have to use this file eventually, but is it necessary in this case? Should it be something that should be avoided unless really necessary? To me, it’s akin to using bs.raw

Choose a reason for hiding this comment

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

There is definitely more boilerplate here and I don't really like that at all. At the same time, you can make the same comments about redux. But underneath all the boilerplate are some good principles. Not that what we have here is great but just like with redux you learn the patterns and you move on. So I kinda see it from that perspective.

@@ -0,0 +1,28 @@
import App, { Container } from 'next/app'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the file I was trying to avoid adding.

Choose a reason for hiding this comment

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

If you play around with next for any considerable amount of time you will probably use this file at some point. I don't see a reason to avoid it when it's provided to allow you to do this very thing.

@@ -0,0 +1,27 @@
module type Config = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does this file mean? It was quite difficult to explain this to a non-react user.

Choose a reason for hiding this comment

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

This was the example I found in the discord channel. As far as what it means, it would probably require some discussion on functors in Ocaml/ReasonML but I would argue this file is not as important as CountContext.re which provides the API for how to create a global value using the context API. I could always add comments to this file that explains things more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree that it will take some discussion of Functors, and module composition (because of the include). Also, this requires a lot of knowledge of React internals.

I think this is rather scary for someone new. I like this example because it does showcase some more advanced functionality. But perhaps it should be it’s own example? Removing the ref from with-reasonml and making the context example being with-reasonml-context ?

Choose a reason for hiding this comment

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

Yeah, this is fine having it in a separate example. I am not that attached like I said before. It's was definitely interesting exploring the context API and how to implement it here.

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 16.4s 15.7s -687ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 17s 17.2s ⚠️ +221ms
node_modules Size 40 MB 40 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB ⚠️ +2 B
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB -1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB ⚠️ +1 B
Build Dir Size 2.37 MB 2.37 MB

@arecvlohe
Copy link

@scull7 If you think it's better served as a separate example then I could create a new one entitled with-reasonreact-context or something like that. It doesn't matter to me either way. It was fun learning how to use context in reason-react with the useReducer/useContext hooks :).

@arecvlohe
Copy link

arecvlohe commented May 16, 2019

@scull7 Do you want to undo my last commit or do you want me to do it. I'll have some time to do it in the morning so just let me know if you want me to.

@scull7
Copy link
Contributor Author

scull7 commented May 16, 2019 via email

@arecvlohe
Copy link

@scull7 Reverted my commit so the branch is clean now

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.7s 15.6s -179ms
node_modules Size 39 MB 40 MB ⚠️ +1.03 MB
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB ⚠️ +1 B
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB -1 B
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 17s 17s -37ms
node_modules Size 39 MB 40 MB ⚠️ +1.03 MB
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB -1 B
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.11 kB -1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB -1 B
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB -2 B
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB -2 B
Serverless pages/index gzip Size 86.3 kB 86.3 kB
Serverless pages/_error Size 334 kB 334 kB -2 B
Serverless pages/_error gzip Size 86.1 kB 86.1 kB ⚠️ +3 B
Serverless pages/routerDirect Size 333 kB 333 kB -2 B
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB -2 B
Serverless pages/withRouter Size 333 kB 333 kB -2 B
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB ⚠️ +1 B
Build Dir Size 2.37 MB 2.37 MB -10 B

@scull7
Copy link
Contributor Author

scull7 commented May 16, 2019 via email

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15s 14.8s -226ms
node_modules Size 39 MB 39 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 16.6s 16.2s -341ms
node_modules Size 39 MB 39 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.11 kB 3.12 kB ⚠️ +1 B
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB ⚠️ +1 B
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB -1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -3 B
Build Dir Size 2.37 MB 2.37 MB

@scull7
Copy link
Contributor Author

scull7 commented May 19, 2019

I think this example is ready to be merged. Are there any objections?

@github-actions
Copy link
Contributor

Stats from current PR

Click to expand stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 14.3s 14.2s -164ms
node_modules Size 40.1 MB 40.1 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Base Rendered Size 1.34 kB 1.34 kB
Build Dir Size 801 kB 801 kB
Click to expand serverless stats
zeit/next.js canary scull7/next.js rework-fix-for-issue-5049 Change
Build Duration 15.6s 15.5s -63ms
node_modules Size 40.1 MB 40.1 MB ⚠️ +8 B
Total Bundle (main, webpack, commons) Size 209 kB 209 kB
Total Bundle (main, webpack, commons) gzip Size 68.3 kB 68.3 kB
Client _app Size 2.54 kB 2.54 kB
Client _app gzip Size 1.05 kB 1.05 kB
Client _error Size 8.19 kB 8.19 kB
Client _error gzip Size 3.12 kB 3.12 kB
Client pages/index Size 288 B 288 B
Client pages/index gzip Size 222 B 222 B
Client pages/link Size 4.83 kB 4.83 kB
Client pages/link gzip Size 2.11 kB 2.11 kB
Client pages/routerDirect Size 411 B 411 B
Client pages/routerDirect gzip Size 296 B 296 B
Client pages/withRouter Size 393 B 393 B
Client pages/withRouter gzip Size 280 B 280 B
Client main Size 23.3 kB 23.3 kB
Client main gzip Size 7.63 kB 7.63 kB
Client commons Size 183 kB 183 kB
Client commons gzip Size 59.4 kB 59.4 kB
Client webpack Size 1.49 kB 1.49 kB
Client webpack gzip Size 769 B 769 B
Serverless pages/link Size 342 kB 342 kB
Serverless pages/link gzip Size 88.7 kB 88.7 kB
Serverless pages/index Size 333 kB 333 kB
Serverless pages/index gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/_error Size 334 kB 334 kB
Serverless pages/_error gzip Size 86.1 kB 86.1 kB -1 B
Serverless pages/routerDirect Size 333 kB 333 kB
Serverless pages/routerDirect gzip Size 86.3 kB 86.3 kB -1 B
Serverless pages/withRouter Size 333 kB 333 kB
Serverless pages/withRouter gzip Size 86.4 kB 86.4 kB -1 B
Build Dir Size 2.37 MB 2.37 MB

@scull7
Copy link
Contributor Author

scull7 commented May 23, 2019

@lfades I believe this example update is also ready to go.

Copy link
Member

@lfades lfades left a comment

Choose a reason for hiding this comment

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

@scull7 Thank you 🙌

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

Successfully merging this pull request may close these issues.

3 participants