-
Notifications
You must be signed in to change notification settings - Fork 131
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
Improve global scope situation with util and lint update #1273
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some years back, we were notified of an issue when the RxPlayer was imported in a Node.JS environment - which has mostly no chance to bring any result unless that environment implements MSE, EME and DOM API - but which was still done due to some logic linked to server-side-rendering. That issue lead to an error, and was due to the RxPlayer refering to the `window` (the global scope accessible in JavaScript in a main thread environment) at the top level (generally done there to check once at script evaluation if various browser API are present), because `window` does not exist in Node.JS environments. What we did at the time is just to check (poorly) if we were in a Node.js environment, and to not rely on `window` if that was the case at those various places. However that was error-prone (we could forget that check) and the only thing preventing mistakes was a script in `scripts/check_nodejs_import_compatibility.js` which wouldn't be able to catch all cases. --- Because this became again a problem when PoCing worker environments, I profited from this project to work on a better solution. Now the global scope is directly provided by an util function of our compat code, which works for NodeJS, JS main thread and JS WebWorker environments, and its usage is enforced by a linter rule which should hopefully catch all `window` usage in the code. I also chose to erase all usage of the term `window` or the shortened `win` alias in code to better communicate the point that we're specifically mean the global scope, regardless of how it is referred to in the current environment.
peaBerberian
force-pushed
the
misc/global-scope-improvement
branch
from
August 31, 2023 12:50
0dd3b0f
to
351683d
Compare
peaBerberian
added a commit
that referenced
this pull request
Aug 31, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Aug 31, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Aug 31, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 15, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 15, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 22, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 26, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 26, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 27, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 27, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 27, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Sep 29, 2023
Improve global scope situation with util and lint update
Merged
peaBerberian
added a commit
that referenced
this pull request
Oct 13, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Oct 13, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Oct 13, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Oct 19, 2023
Improve global scope situation with util and lint update
peaBerberian
added a commit
that referenced
this pull request
Oct 26, 2023
Improve global scope situation with util and lint update
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some years back, we were notified of an issue when the RxPlayer was imported in a Node.JS environment - which has mostly no chance to bring any result unless that environment implements MSE, EME and DOM API - but which was still done due to some application logic linked to server-side-rendering.
That issue lead to an error, and was due to the RxPlayer refering to the
window
(the global scope accessible in JavaScript in a main thread environment) at the top level (generally done there to check once at script evaluation if various browser API are present), becausewindow
does not exist in Node.JS environments.What we did at the time is just to check (poorly) if we were in a Node.js environment, and to not rely on
window
if that was the case at those various places. However that was error-prone (we could forget that check) and the only thing preventing mistakes was a script inscripts/check_nodejs_import_compatibility.js
which wouldn't be able to catch all cases.Because this became again a problem when PoCing worker environments, I profited from this project to work on a better solution.
Now the global scope is directly provided by an util function of our compat code, which works for NodeJS, JS main thread and JS WebWorker environments, and its usage is enforced by a linter rule which should hopefully catch most
window
usage in the code.I also chose to erase all usage of the term
window
or the shortenedwin
alias in code to better communicate the point that we're specifically mean the global scope, regardless of how it is referred to in the current environment.