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: fatal error when current JS is not inside script tag #2229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions client-src/default/utils/createSocketUrl.js
Expand Up @@ -16,8 +16,10 @@ function createSocketUrl(resourceQuery) {
// Else, get the url from the <script> this file was called with.
let scriptHost = getCurrentScriptSource();

// eslint-disable-next-line no-useless-escape
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
if (scriptHost) {
// eslint-disable-next-line no-useless-escape
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
}
urlParts = url.parse(scriptHost || '/', false, true);
}

Expand Down
2 changes: 2 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Expand Up @@ -13,6 +13,8 @@ describe('createSocketUrl', () => {
// TODO: comment out after the major release
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
// 'file://filename',
// eslint-disable-next-line no-undefined
undefined,
];

samples.forEach((url) => {
Expand Down