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

Watch for changes to html.js #1473

Merged
merged 12 commits into from Jul 13, 2017
Merged

Watch for changes to html.js #1473

merged 12 commits into from Jul 13, 2017

Conversation

felixjung
Copy link
Contributor

@felixjung felixjung commented Jul 11, 2017

Addresses #1442.

@KyleAMathews, I think we can address the configuration via socket support in a separate topic branch?

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 11, 2017

Deploy preview ready!

Built with commit ee15e2c

https://deploy-preview-1473--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 11, 2017

Deploy preview ready!

Built with commit ee15e2c

https://deploy-preview-1473--gatsbygram.netlify.com

@KyleAMathews
Copy link
Contributor

Won't StaticSiteGeneratorPlugin automatically rebuild all pages?

No check out develop-html.js — it only builds one index.html page.

The only thing I see right now is to include socket.io and push an event to the client whenever index.html has been rebuilt. The client can then refresh the page.

Yeah exactly. Gatsby's entry for development would connect to the dev server and then would refresh when instructed.

@KyleAMathews
Copy link
Contributor

Looking good so far!

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 11, 2017

Deploy preview ready!

Built with commit ee15e2c

https://deploy-preview-1473--gatsbyjs.netlify.com

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Jul 12, 2017

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit d607b3e81176053c02993fc66685579218834d0e

https://app.netlify.com/sites/using-glamor/deploys/5965d5216f4c507bc0303652

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Jul 12, 2017

Deploy preview failed.

Built with commit 1c2b4a1101cde779e723007cde9320364fb7206e

https://app.netlify.com/sites/using-postcss-sass/deploys/59669e7b424ef23c4ea8996e

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit d607b3e81176053c02993fc66685579218834d0e

https://app.netlify.com/sites/image-processing/deploys/5965d5216f4c507bc030364f

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Jul 12, 2017

Deploy preview failed.

Built with commit ee15e2c

https://app.netlify.com/sites/using-contentful/deploys/5967ea667960b10804296eb8

@felixjung
Copy link
Contributor Author

OK. This works end-to-end now. @KyleAMathews, I'm not sure if I put the client code in the right places. Could you review the code please? ☺️

@felixjung
Copy link
Contributor Author

Hah, I guess I still have to add some tests 😉

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Looks great!

Tests would be fantastic too!

@@ -8,6 +8,13 @@ window.___emitter = require(`./emitter`)
// Let the site/plugins run code very early.
apiRunner(`onClientEntry`)

if (process.env.NODE_ENV === `development`) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary as this file is only used in development.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good to know. I wasn't sure, but I guess I should have taken a closer look at the webpack config 😁

@felixjung
Copy link
Contributor Author

I've added tests for the src/util/path.js module. I have 0️⃣ clue how to test the develop server though 😞 That being said, I don't see too many tests in there anyway 😂

@felixjung
Copy link
Contributor Author

Wow, getting those windows tests right took longer than it should have 🙄

@KyleAMathews
Copy link
Contributor

Just tested it, worked perfectly! Slick work!

The only change I'd suggest making is to add a console.log when Gatsby starts rebuilding the html.js file so the user knows something is happening and why.

@KyleAMathews
Copy link
Contributor

I'm going to do another minor release now and want this in it so I'll just merge this but please do the above in a follow-up PR.

Thanks for taking this on! Hot reload all the things :-)

@KyleAMathews KyleAMathews merged commit 7ed0389 into gatsbyjs:master Jul 13, 2017
@felixjung
Copy link
Contributor Author

Woohoo! Yeah, what you say makes a lot of sense 😀.

sebastienfi added a commit that referenced this pull request Aug 2, 2017
This fails on Windows. Doing a check for filename validity on Windows [is costly](https://github.com/sindresorhus/filename-reserved-regex/blob/master/index.js) and should probably be done by the user but in this case if the file doesn't exists then so does the link.
Surrounding this with a `try...catch` solves the issue with no further consequences.

This should be solved once [libuv v2.0](https://github.com/libuv/libuv) will be out.

Report of the error : 
```
fs.js:1103
  return binding.unlink(pathModule._makeLong(path));
                 ^

Error: ENOENT: no such file or directory, unlink 'C:\{your-path}\public\render-page.js'
    at Error (native)
    at Object.fs.unlinkSync (fs.js:1103:18)
    at C:\{your-path}\node_modules\gatsby\dist\utils\develop-html.js:59:30
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:194:14)
    at Compiler.emitRecords (C:\{your-path}\node_modules\webpack\lib\Compiler.js:282:37)
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:187:11)
    at C:\{your-path}\node_modules\webpack\lib\Compiler.js:275:11
    at Compiler.applyPluginsAsync (C:\{your-path}\node_modules\tapable\lib\Tapable.js:60:69)
    at Compiler.afterEmit (C:\{your-path}\node_modules\webpack\lib\Compiler.js:272:8)
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:267:14)
    at C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:52:16
    at done (C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:246:17)
    at C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:44:16
    at C:\{your-path}\node_modules\graceful-fs\graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:123:15)
```

Related to #1473 #1442
KyleAMathews pushed a commit that referenced this pull request Aug 8, 2017
This fails on Windows. Doing a check for filename validity on Windows [is costly](https://github.com/sindresorhus/filename-reserved-regex/blob/master/index.js) and should probably be done by the user but in this case if the file doesn't exists then so does the link.
Surrounding this with a `try...catch` solves the issue with no further consequences.

This should be solved once [libuv v2.0](https://github.com/libuv/libuv) will be out.

Report of the error : 
```
fs.js:1103
  return binding.unlink(pathModule._makeLong(path));
                 ^

Error: ENOENT: no such file or directory, unlink 'C:\{your-path}\public\render-page.js'
    at Error (native)
    at Object.fs.unlinkSync (fs.js:1103:18)
    at C:\{your-path}\node_modules\gatsby\dist\utils\develop-html.js:59:30
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:194:14)
    at Compiler.emitRecords (C:\{your-path}\node_modules\webpack\lib\Compiler.js:282:37)
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:187:11)
    at C:\{your-path}\node_modules\webpack\lib\Compiler.js:275:11
    at Compiler.applyPluginsAsync (C:\{your-path}\node_modules\tapable\lib\Tapable.js:60:69)
    at Compiler.afterEmit (C:\{your-path}\node_modules\webpack\lib\Compiler.js:272:8)
    at Compiler.<anonymous> (C:\{your-path}\node_modules\webpack\lib\Compiler.js:267:14)
    at C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:52:16
    at done (C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:246:17)
    at C:\{your-path}\node_modules\webpack\node_modules\async\lib\async.js:44:16
    at C:\{your-path}\node_modules\graceful-fs\graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:123:15)
```

Related to #1473 #1442
@jlengstorf
Copy link
Contributor

Hiya @felixjung! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

@felixjung
Copy link
Contributor Author

Thanks a ton @jlengstorf! I had heard about this in various podcasts, but wasn’t expecting it anymore. What a nice surprise. Keep it up!

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.

None yet

4 participants