Skip to content

Conversation

@smashercosmo
Copy link
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

Please Describe Your Changes

This PR adds 'waitForBundleReady' option, which prevents all server middlewares to run until bundle is fully compiled. Same functionality is supported by webpack-dev-middleware via serverSideRender option

@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from 9687a2a to 04722e1 Compare January 29, 2019 12:13
@smashercosmo smashercosmo changed the title feat: add waitForBundle ready option feat: add waitForBundleReady option Jan 29, 2019
@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from 04722e1 to 9bbce13 Compare January 29, 2019 12:16
Copy link
Collaborator

@matheus1lva matheus1lva left a comment

Choose a reason for hiding this comment

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

For what i could see from previous comments on old issues, this can decrease the number of weird errors, specially from websocket side.

Also, don't forget to update the typescript definition file. Almost the same as the joi validation.

@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from 9bbce13 to a071e80 Compare January 29, 2019 12:24
@smashercosmo
Copy link
Contributor Author

@playma256 thx for review. definitions are updated now.

@shellscape
Copy link
Owner

Great work and thank you for the PR. Please give me some time to consider the verbiage of the option name and documentation. In the mean time, it looks like Node 10 tests are failing, and those need to be resolved.

@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from a071e80 to e7d6238 Compare January 29, 2019 16:28
@smashercosmo
Copy link
Contributor Author

Alright. Tests are passing now.

@smashercosmo
Copy link
Contributor Author

I'm not quite sure, how to write test to cover bundle rebuilding case.

@shellscape
Copy link
Owner

I'm not quite sure, how to write test to cover bundle rebuilding case.

You'd have to overwrite a file that's in the bundle to force a rebuild, and then wait for that rebuild to finish. I think we have some tests that do something similar, but if it works for the first build. it's probably going to work for the second, third, etc

@sibelius please give this PR a look when you get the chance

Copy link
Owner

@shellscape shellscape left a comment

Choose a reason for hiding this comment

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

A few semantic changes I'd like to make.

@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from 8c7e965 to 570f855 Compare January 30, 2019 12:29
@smashercosmo smashercosmo force-pushed the wait-for-bundle-ready branch from 570f855 to a38305e Compare January 30, 2019 12:34
@smashercosmo smashercosmo changed the title feat: add waitForBundleReady option feat: add waitForBuild option Jan 30, 2019
@smashercosmo
Copy link
Contributor Author

Ready for final review

matheus1lva
matheus1lva previously approved these changes Jan 30, 2019
Copy link
Collaborator

@matheus1lva matheus1lva left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the effort!! 🥂

The coverage error reminds me i have to get home today and merge my tests! LOL

lib/index.js Outdated
options.static = [];
}

if (options.waitForBuild) {
Copy link
Owner

Choose a reason for hiding this comment

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

why do we need a done handler here as well as on line 170? is it to catch the first build and then any subsequent builds?

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

lib/server.js Outdated

if (waitForBuild) {
app.use(async (ctx, next) => {
if (!this.compiled) {
Copy link
Owner

Choose a reason for hiding this comment

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

since the next line is just awaiting a promise, we don't need a logical check here. we can always await the promise. once the promise is resolved, this will pass-through. I'll push this change to your branch.

@shellscape
Copy link
Owner

I'm working on a few changes to the PR now. One big problem that strikes me is probably going to be MultiCompilers. If there are several compilers running at once, and WPS is attached to each, they're all going to be tracking when the build is done, but only the first compiler will block the middleware. At that point the middleware could continue on even as other builds are waiting to finish. We may have to accept that limitation at the moment, and circle back to it if someone raises the issue.

@shellscape shellscape dismissed matheus1lva’s stale review February 3, 2019 14:08

please review again

if (this.options.waitForBuild) {
// track the first build of the bundle
this.state.compiling = new Promise((resolve) => {
this.once('done', () => resolve());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be shortened to this.once('done', resolve);

Copy link
Owner

Choose a reason for hiding this comment

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

it could :) in certain situations I like to be a bit more verbose.

// track subsequent builds from watching
this.on('invalid', () => {
this.state.compiling = new Promise((resolve) => {
this.once('done', () => resolve());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

@shellscape shellscape merged commit 64f2a80 into shellscape:master Feb 4, 2019
@shellscape shellscape mentioned this pull request Mar 19, 2019
18 tasks
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.

3 participants