Skip to content

Commit c483a8c

Browse files
committed
Migrating from Node's deprecated url API to browser's URL
Related to #16292 Signed-off-by: Bekliev Parviz <nightkon95@gmail.com>
1 parent 3e57378 commit c483a8c

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
"react": "^16.14.0",
6767
"react-dom": "^16.14.0",
6868
"sanitize-html": "github:apostrophecms/sanitize-html#3c7f93f2058f696f5359e3e58d464161647226db",
69-
"ua-parser-js": "^0.7.23",
70-
"url": "^0.11.0"
69+
"ua-parser-js": "^0.7.23"
7170
},
7271
"devDependencies": {
7372
"@babel/core": "^7.12.10",

src/vector/app.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import React from 'react';
2323
// this incidentally means we can forget our React imports in JSX files without penalty.
2424
window.React = React;
2525

26-
import url from 'url';
2726
import * as sdk from 'matrix-react-sdk';
2827
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
2928
import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler';
@@ -120,14 +119,12 @@ function onTokenLoginCompleted() {
120119
// if we did a token login, we're now left with the token, hs and is
121120
// url as query params in the url; a little nasty but let's redirect to
122121
// clear them.
123-
const parsedUrl = url.parse(window.location.href, true);
122+
const url = new URL(window.location.href);
124123

125-
parsedUrl.search = null; // to make `url.format` ignores `search` property and uses `query` instead
126-
delete parsedUrl.query['loginToken'];
124+
url.searchParams.delete('loginToken');
127125

128-
const formatted = url.format(parsedUrl);
129-
console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`);
130-
window.history.replaceState(null, "", formatted);
126+
console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`);
127+
window.history.replaceState(null, "", url.href);
131128
}
132129

133130
export async function loadApp(fragParams: {}) {

src/vector/platform/WebPlatform.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix
2626
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
2727
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
2828

29-
import url from 'url';
3029
import UAParser from 'ua-parser-js';
3130

3231
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
@@ -184,17 +183,8 @@ export default class WebPlatform extends VectorBasePlatform {
184183

185184
getDefaultDeviceDisplayName(): string {
186185
// strip query-string and fragment from uri
187-
const u = url.parse(window.location.href);
188-
u.protocol = "";
189-
u.search = "";
190-
u.hash = "";
191-
// Remove trailing slash if present
192-
u.pathname = u.pathname.replace(/\/$/, "");
193-
194-
let appName = u.format();
195-
// Remove leading slashes if present
196-
appName = appName.replace(/^\/\//, "");
197-
// `appName` is now in the format `develop.element.io`.
186+
const url = new URL(window.location.href);
187+
const appName = [url.host, url.pathname].join(''); // `appName` in the format `develop.element.io/abc/xyz`
198188

199189
const ua = new UAParser();
200190
const browserName = ua.getBrowser().name || "unknown browser";

yarn.lock

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8890,16 +8890,7 @@ postcss-attribute-case-insensitive@^4.0.1:
88908890
postcss "^7.0.2"
88918891
postcss-selector-parser "^6.0.2"
88928892

8893-
postcss-calc@^7.0.1:
8894-
version "7.0.5"
8895-
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
8896-
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==
8897-
dependencies:
8898-
postcss "^7.0.27"
8899-
postcss-selector-parser "^6.0.2"
8900-
postcss-value-parser "^4.0.2"
8901-
8902-
postcss-calc@^7.0.5:
8893+
postcss-calc@^7.0.1, postcss-calc@^7.0.5:
89038894
version "7.0.5"
89048895
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
89058896
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==

0 commit comments

Comments
 (0)