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

feat: deprecate window global #22057

Merged
merged 4 commits into from
Jan 24, 2024
Merged

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Jan 23, 2024

This commit deprecates window global and adds deprecation
notice on each use of window.

We decided to proceed with removal of window global variable in Deno 2.0. There's a lot of code
in the wild that uses pattern like this:

if (typeof window !== "undefined) {
  ...
}

to check if the code is being run in browser. However, this check passes fine in Deno and
most often libraries that do this check try to access some browser API that is not available
in Deno, or use DOM APIs (which are also not available in Deno).

This situation has occurred multiple times already
and it's unfeasible to expect the whole ecosystem to migrate to new check (and even if that
happened there's a ton of code that's already shipped and won't change).

The migration is straightfoward - replace all usages of window with globalThis or self.
When Deno encounters use of window global it will now issue a warning, steering users
towards required changes:

Warning
├ Use of deprecated "window" API.
│
├ This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.
│
├ Suggestion: Use `globalThis` or `self` instead.
│
├ Suggestion: You can provide `window` in the current scope with: `const window = globalThis`.
│
└ Stack trace:
  └─ at file:///Users/ib/dev/deno/foo.js:7:1

Screenshot 2024-01-23 at 22 18 24

Ref #13367.

@bartlomieju bartlomieju added this to the 1.40 milestone Jan 23, 2024
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit 930ce20 into denoland:main Jan 24, 2024
14 checks passed
@bartlomieju bartlomieju deleted the deprecate_window branch January 24, 2024 13:21
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Jan 24, 2024
bartlomieju added a commit that referenced this pull request Jan 24, 2024
This reverts commit 930ce20.

This is producing false-positives that are not actionable to users.
We're gonna address this in another release.
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.

4 participants