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

fix(client): stricter reg exp to redirect sockjs client path #2069

Merged
merged 6 commits into from Jul 11, 2019

Conversation

knagaitsev
Copy link
Collaborator

  • 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

Fixes problem introduced by #2015 using a stricter reg exp.

I added an iframe e2e test because the issue came up from users using iframe mode: #2006

Breaking Changes

None

Additional Info

@codecov
Copy link

codecov bot commented Jun 25, 2019

Codecov Report

Merging #2069 into master will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2069      +/-   ##
==========================================
+ Coverage   94.56%   94.65%   +0.08%     
==========================================
  Files          32       32              
  Lines        1215     1215              
  Branches      340      340              
==========================================
+ Hits         1149     1150       +1     
+ Misses         64       63       -1     
  Partials        2        2
Impacted Files Coverage Δ
lib/Server.js 97.37% <0%> (+0.21%) ⬆️

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 bdf8444...c8d90ce. Read the comment docs.

);
}),
new webpack.NormalModuleReplacementPlugin(
/^\.\/clients\/SockJSClient$/,
Copy link
Member

Choose a reason for hiding this comment

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

We need search way how we can check what module was loaded from our client-src - it is right way don't break other code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean to test that it is loading the correct module in the webpack compilation? Could we run this webpack config in a test, look at the webpack CLI output, and see if it contains the right path?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but it can solved using NormalModuleReplacementPlugin as you use, just need more checks (need check context contains 'webpack-dev-server/client-src' and rewrite only in this case)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@evilebottnawi I did something like this, except instead I matched '/client-src/default', because it is possible the dev server is not in a webpack-dev-server directory if someone clones it into a different named directory. If we want to be very strict about it, we could match against path.resolve to get the exact context we want, but I'm afraid that could result in some problem.

Also, I included backwards slash (\\) in my matching string because windows seems to use that for the context paths

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.

Just check if (resource.context.startsWith(process.cwd())) { }, we need rewrite clients only for webpack-dev-server, for other package it should be not rewritting

@knagaitsev
Copy link
Collaborator Author

Just check if (resource.context.startsWith(process.cwd())) { }, we need rewrite clients only for webpack-dev-server, for other package it should be not rewritting

Done. Good solution!

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.

/cc @hiroppy

@hiroppy hiroppy merged commit d3da508 into webpack:master Jul 11, 2019
knagaitsev added a commit to knagaitsev/webpack-dev-server that referenced this pull request Jul 31, 2019
…#2069)

* fix(client): stricter reg exp to redirect sockjs client path

* fix(client): check resource context for normal module replacement

* fix(client): remove dev server string from context path

* fix(client): remove console logs

* fix(client): fixed resource context match to use cwd
@knagaitsev knagaitsev added gsoc Google Summer of Code scope: ws(s) labels Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc Google Summer of Code scope: ws(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants