Skip to content

fix: disable socket injection when hot & liveReload are disabled #2133

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

Closed
wants to merge 19 commits into from

Conversation

EslamHiko
Copy link
Member

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Yes

Motivation / Use-Case

Solves : #1831

Breaking Changes

No

Additional Info

@codecov
Copy link

codecov bot commented Jul 18, 2019

Codecov Report

Merging #2133 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2133      +/-   ##
==========================================
+ Coverage   92.56%   92.58%   +0.01%     
==========================================
  Files          33       33              
  Lines        1265     1268       +3     
  Branches      361      363       +2     
==========================================
+ Hits         1171     1174       +3     
  Misses         87       87              
  Partials        7        7
Impacted Files Coverage Δ
lib/Server.js 97.35% <100%> (ø) ⬆️
client-src/default/index.js 92.39% <100%> (+0.16%) ⬆️

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 5c5024c...324b006. Read the comment docs.

@@ -24,7 +24,8 @@ Array [

exports[`Client iframe console.log liveReload disabled 1`] = `
Array [
"Hey.",
"Failed to load resource: the server responded with a status of 404 (Not Found)",
"Failed to load resource: the server responded with a status of 404 (Not Found)",
Copy link
Member

@alexander-akait alexander-akait Jul 18, 2019

Choose a reason for hiding this comment

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

Looks something wrong expected

Copy link
Member Author

Choose a reason for hiding this comment

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

yes liveReload is disabled and hot is disabled too that's why the WebSocket is not working

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is possible that this could be a variable number of 404 error messages, since the client keeps retrying to connect. Maybe this should be handled some way for this particular test?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Loonride any idea to handle these 404 errors?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Loonride any idea to handle these 404 errors?

@EslamHiko Sorry I missed your reply, it seems tests generally pass as the timing is consistent to only output the error message twice, but just in case:

You could check that every element in that array is the same. Then make the snapshot only test the first element of the output array. This will allow for a variable number of the same error message.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good job! One note

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

@@ -60,3 +66,99 @@ describe('WebsocketClient', () => {
});
});
});

describe('websocket client injection', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be moved to the test/server directory. Either in Server.test.js, or possibly a new test file of its own. @evilebottnawi thoughts on where it should go exactly?

Copy link
Member

Choose a reason for hiding this comment

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

@EslamHiko yep, let's move this test to test/server
@Loonride maybe test/server/hot-and-liveReload-integration, no idea how better naming this 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@Loonride @evilebottnawi okay, will move it to test/server/socket-injection what do you think about the name? 😅

Copy link
Member

Choose a reason for hiding this comment

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

test/server/socket-injection.test.js 👍

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

One note and we can merge this 👍

done();
});
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Let's add test where hot: false, liveReload: true for explicit check

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

@@ -25,6 +25,9 @@ Array [
exports[`Client console.log liveReload disabled 1`] = `
Array [
"Hey.",
"Failed to load resource: the server responded with a status of 404 (Not Found)",
"[WDS] Disconnected!",
Copy link
Member Author

Choose a reason for hiding this comment

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

should I add a check to disable "[WDS] Disconnected!" message when hot & liveReload are disabled ? @Loonride @evilebottnawi

Copy link
Member

Choose a reason for hiding this comment

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

I think yes, better output message like [WDS] hot and live reload was disables

log.error('[WDS] Disconnected!');
if (options.hot || options.liveReload) log.error('[WDS] Disconnected!');
else
{log.error('[WDS] Hot Module Replacement & Live Reloading are disabled!');}
Copy link
Member

@alexander-akait alexander-akait Jul 24, 2019

Choose a reason for hiding this comment

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

if (condition) { 
  // Logic
} else {
  // Logic
}

@EslamHiko EslamHiko closed this Jul 24, 2019
@EslamHiko EslamHiko reopened this Jul 24, 2019
@codecov
Copy link

codecov bot commented Jul 24, 2019

Codecov Report

Merging #2133 into v4 will increase coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##               v4    #2133      +/-   ##
==========================================
+ Coverage   93.77%   93.93%   +0.16%     
==========================================
  Files          34       34              
  Lines        1333     1287      -46     
  Branches      381      368      -13     
==========================================
- Hits         1250     1209      -41     
+ Misses         81       77       -4     
+ Partials        2        1       -1     
Impacted Files Coverage Δ
client-src/default/index.js 92.39% <100.00%> (+0.16%) ⬆️
lib/Server.js 97.32% <100.00%> (+0.53%) ⬆️
lib/servers/WebsocketServer.js 89.47% <0.00%> (-4.65%) ⬇️
lib/utils/routes.js 92.50% <0.00%> (-0.98%) ⬇️
lib/utils/runOpen.js 100.00% <0.00%> (ø)
lib/utils/addEntries.js 100.00% <0.00%> (ø)
lib/utils/normalizeOptions.js 100.00% <0.00%> (ø)
client-src/default/utils/createSocketUrl.js 100.00% <0.00%> (ø)
client-src/clients/WebsocketClient.js 57.89% <0.00%> (+0.39%) ⬆️
... and 2 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 375ab23...0787620. Read the comment docs.

@alexander-akait
Copy link
Member

/cc @hiroppy @Loonride

@@ -737,7 +737,9 @@ class Server {
this.hostname = hostname;

return this.listeningApp.listen(port, hostname, (err) => {
this.createSocketServer();
if (this.options.hot || this.options.liveReload !== false) {
Copy link
Member

Choose a reason for hiding this comment

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

- if (this.options.hot || this.options.liveReload !== false) {
+ if (this.options.hot || this.options.liveReload) {

Copy link
Member Author

Choose a reason for hiding this comment

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

@hiroppy sorry for my late reply but I think if I changed it, it won't create the socket server if options.liveReload was undefined the default value. I suggest making little refactor and write this.options.liveReload = this.options.liveReload !== false at the beginning of the constructor and replace all this.options.liveReload !== false with this.options.liveReload.

Copy link
Member

Choose a reason for hiding this comment

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

/cc @hiroppy

Copy link
Member

@hiroppy hiroppy Sep 24, 2019

Choose a reason for hiding this comment

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

ok, we will fix this in the next version.

@knagaitsev
Copy link
Collaborator

@evilebottnawi Is it possible this should be on next? It is a good idea, but it is conceivable that users might still want the socket server running but do not have the right server settings. For example, someone could have the server running and are expecting to connect to the socket with a custom client not served by webpack-dev-server.

@alexander-akait
Copy link
Member

@Loonride hm, what is use case for this action?

@knagaitsev
Copy link
Collaborator

@Loonride hm, what is use case for this action?

I can't think of a good use case. I was thinking hypothetically someone could connect to the socket server without using the served client, but there is likely no use for this.

Anyway, LGTM.

@EslamHiko
Copy link
Member Author

/cc @hiroppy @evilebottnawi @Loonride CI is green 😄

@alexander-akait
Copy link
Member

/cc @EslamHiko we merge this for next release because #2133 (comment), anyway thanks for PR, we will try to release next version on next/next-next week (we are working on webpack-dev-middleware)

knagaitsev and others added 6 commits April 27, 2020 14:21
* chore(deps): upgrade chokidar

* chore(deps): switch to promise method without async for close

* chore(ci): remove node v6

* chore(deps): fix issue of closing watchers before middleware

* chore(deps): upgrade chokidar to v3.4.0
* chore(deps): upgrade deps

* style: run prettier

* test: update

* ci: remove Node@8

* test(cli): add windows support

* chore(deps): downgrade puppeteer

* chore(deps): downgrade some deps

* fix(hot): enable hot option as default (webpack#2546)

BREAKING CHANGE: the `hot` option is `true` by default, the `hotOnly` option was removed in favor `{ hot: 'only' }`

* fix: remove lazy and filename options (webpack#2544)

BREAKING CHANGE: `lazy` and `filename` options was removed
knagaitsev and others added 6 commits May 1, 2020 20:48
BREAKING CHANGE: switch default transportMode to ws
BREAKING CHANGE: the `client` now in `default` directory
BREAKING CHANGE: the `setup` was removed, `before` and `after` options were renamed to `onBeforeSetupMiddleware` and `onAfterSetupMiddleware`
@alexander-akait
Copy link
Member

/cc @EslamHiko Can you send a PR for v4?

@EslamHiko EslamHiko changed the base branch from master to v4 May 13, 2020 05:20
@EslamHiko EslamHiko force-pushed the disable-sock-injection branch from 80abcb2 to 0787620 Compare May 13, 2020 05:20
@EslamHiko EslamHiko changed the base branch from v4 to master May 13, 2020 05:24
@EslamHiko EslamHiko changed the base branch from master to v4 May 13, 2020 05:25
@EslamHiko
Copy link
Member Author

EslamHiko commented May 13, 2020

@evilebottnawi I failed to rebase & created a fresh PR here: #2601

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.

6 participants