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

node v21.0.0 breaks with xterm: Cannot read properties of undefined (reading 'includes') #4850

Closed
davidfiala opened this issue Oct 19, 2023 · 2 comments
Assignees
Labels
type/debt Technical debt that could slow us down in the long run
Milestone

Comments

@davidfiala
Copy link
Contributor

node v21.0.0 introduces the navigator object where it used to be undefined.

Which causes issues in src/common/Platform.ts:

export const isNode = (typeof navigator === 'undefined') ? true : false;
const userAgent = (isNode) ? 'node' : navigator.userAgent;
const platform = (isNode) ? 'node' : navigator.platform;

export const isFirefox = userAgent.includes('Firefox');

There was discussion on whether using navigator to detect node here: nodejs/node#47769 (comment) but ultimately they concluded that since Deno has introduced a navigator object, so can node.

I often see checks like this instead:

const isNode = (typeof process !== 'undefined');
// or
const isNode = (typeof global !== 'undefined');

which will work for v21 and below.

@Tyriar Tyriar added this to the 5.4.0 milestone Oct 19, 2023
@Tyriar Tyriar self-assigned this Oct 19, 2023
@davidfiala
Copy link
Contributor Author

Some recent updates on the node side: As more projects have noticed breakages introduced by adding navigator in v21.0.0, the node team recently merged in navigator.userAgent in v21.1.0.

If you'd like, I could add another PR to detect that, but I'd also have to account for a few other cases which will make it look a bit weird for the next few years.

While my PR above with const isNode = (typeof process !== 'undefined'); works for all versions AFAIK, it's always possible this may break again in the future.

Detection edge cases we'd need to support for a while:

  • < v21.0.0 no process object, no navigator object
  • == v21.0.0 no process object, yes navigator, no navigator.userAgent
  • >= v21.1.0 no process object, yes navigator, yes navigator.userAgent
  • future process object could change?
  • another 3p library Or what if another library creates a global process object, thus confusing xterm's detection logic

It's certainly fine to do nothing and keep things as are, as I doubt any change will be rapid. My offer would be to provide a PR to add a back-stop so that if navigator.userAgent exists, we'd string match for Node.js. And likewise, we wouldn't assume that the existence a of global process implies node unless there also is no navigator.userAgent present. LMK if you'd like this change.

Refs:

@Tyriar
Copy link
Member

Tyriar commented Nov 27, 2023

@davidfiala thanks for looking into this, ideally we'd like whatever is the most future proof if you want to contribute an improvement 🙂

@Tyriar Tyriar added the type/debt Technical debt that could slow us down in the long run label Nov 27, 2023
@Tyriar Tyriar removed this from the 5.4.0 milestone Nov 27, 2023
@Tyriar Tyriar added this to the 5.4.0 milestone Mar 1, 2024
@Tyriar Tyriar closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/debt Technical debt that could slow us down in the long run
Projects
None yet
Development

No branches or pull requests

2 participants