Skip to content

Discourage use of 'window' and 'document' #2874

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

Merged
merged 1 commit into from
Apr 20, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Apr 6, 2020

This should help us find issues such as #2870 before they surface in ReactNative and WebWorkers.

@google-oss-bot
Copy link
Contributor

return typeof document !== 'undefined' ? document : null;
}

get window(): Window | null {
// `window` is not always available, e.g. in ReactNative and WebWorkers.
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by comment: should this fall back on self in a web worker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know and we should be careful if we want to make this change. FWIW, this doc says to always use self: https://developer.mozilla.org/en-US/docs/Web/API/Window/self

This works because JS in browsers prefixes any unknown globals with window and window.self seems to be a thing.

Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

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

LGTM

@schmidt-sebastian schmidt-sebastian merged commit 507da7a into master Apr 20, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/ban branch April 20, 2020 17:58
@firebase firebase locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants