-
Notifications
You must be signed in to change notification settings - Fork 535
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
Use WHATWG URL instead of Node's built-in url module #8760
Conversation
de5703a
to
afa4e63
Compare
const parsedUrl = parse(resolvedUrl.url); | ||
const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : []; | ||
const parsedUrl = new URL(resolvedUrl.url); | ||
const [, tenantId, documentId] = parsedUrl.pathname ? parsedUrl.pathname.split("/") : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~url.parse().path
is not the same as new URL().pathname
. The former includes the query string, while the latter does not. This code change is therefor a behavior change, but I don't think it matters because the query isn't parsed. Moreover, similar functions exist elsewhere in our codebase, and in those cases, the existing code already used .pathname
.
Wrong.
46e8cf4
to
1d2c7e7
Compare
24fa4a0
to
b5c3f1a
Compare
@@ -16,7 +16,7 @@ module.exports = { | |||
"/**/dist/test/*.spec.js" | |||
], | |||
|
|||
testEnvironment: "jsdom", | |||
testEnvironment: "node", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to get the tests passing, but I don't understand why or if this is really a safe change.
Given the complexity of (4), I'm inclined to do (3) as a short-term solution. Regardless that will be in a separate PR. |
Summary
Partially addresses #8725.
Webpack 5, Vite, and other modern bundlers don't include Node polyfills by default, and several of the functions (
parse
,resolve
) have been deprecated since Node 11 in favor of the WHATWG URL spec.This PR removes our use of the
url
module, replacing it with an isomorphic implementation.Updates
2022-02-03: The whatwg-url package worked almost everywhere. The exception was the end-to-end-tests project, which needed support for relative URLs without a base, so there I used the iso-url package. This only affects the test project.
2022-01-31: The browser URL implementation has a bug, it seems. See an example in the playground here.
This code should print true, but it's false in the latest Edge and Firefox.
fluidScheme.pathname
is returning"//localhost:3000/tenantId/1643676316659"
. It should return"/tenantId/1643676316659"
.Anyway, I've switched to whatwg-url and am going to use that everywhere. I trust it more.
2022-01-18: Testing the WHATWG URL API -- I'm unclear if it will "just work" across all the build targets we care about. But all local testing passes.
2022-01-14: Debugging test failures.