Skip to content

Conversation

alfaproject
Copy link

@alfaproject alfaproject commented Sep 1, 2021

Related JIRA ticket with more details: https://jira.mongodb.org/browse/NODE-3581

I've just realised after doing this PR that you decided to use the whatwg-url npm package due to some browser issue. Is there any more information about this? Is it because of V8 or some other engine? I'm asking because there has been a few fixes since then.

In any case, browser quirks are usually handled by polyfills but if we really want a shim maybe we can use this instead which is much smaller https://github.com/lukeed/url-shim and I believe meets all requirements.

@addaleax
Copy link
Collaborator

addaleax commented Sep 1, 2021

I've just realised after doing this PR that you decided to use the whatwg-url npm package due to some browser issue. Is there any more information about this?

Yeah, this was causing trouble for us when we were upgrading the driver in MongoDB Compass, because Compass is an Electron app and thus uses the Chrome URL implementation – #1 has a bit more information.

Specifically, in browsers, mongodb connection strings will not be parsed like e.g. HTTP urls, and instead everything after mongodb:// is considered a pathname (i.e. host, port, username, password, search string are all unpopulated).

Also, all relevant environments (Node.js 11+ and browsers) have TextEncoder/TextDecoder available globally, and I would not be eager to go out of our way to support quirks that are jsdom-specific. We do use this package in an environment where neither URL nor TextEncoder/TextDecoder are natively available; we polyfill the latter for that, which is not hard since we only need UTF-8 support: https://github.com/mongodb-js/mongosh/blob/23bb10be32aa0776cefd4ba19cd30cd6e1c52c10/packages/service-provider-core/src/textencoder-polyfill.ts

Is it because of V8 or some other engine?

JS engines don’t have anything to do with this, this is purely about URL implementations. I don’t know why the browser ones differ from the whatwg-url package and the Node.js implementation.

but if we really want a shim maybe we can use this instead which is much smaller https://github.com/lukeed/url-shim and I believe meets all requirements.

I think using a shim that only works in browsers and isn’t spec-compliant is a non-started, tbh.

@alfaproject
Copy link
Author

Sadly, every Jest user developing browser or electron-like apps will suffer now. I setup Jest globals for TextEncoder so that we could keep testing and be able to update the mongodb driver but it doesn't change the fact that a breaking change update was introduced in a patch release of the driver.

You guys might want to at least make a note in the change log so that if anyone else has the same issue they don't need to go down the same rabbit hole. (;

I get your points tho, so I'll close this and just add another comment in the related JIRA issue for this thread. Thank you for the feedback

@alfaproject alfaproject closed this Sep 1, 2021
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.

2 participants