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

v4: Remove next-tick dependency #1312

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

peaBerberian
Copy link
Collaborator

For years, we had a unique external dependency (the only non-dev dependency) called "next-tick" allowing us to schedule callbacks in micro-tasks, either to provide asynchronous browser API shims or for some specific logic where we would prefer to bring some asynchronicity in without the need of bringing the event loop into this.

We were not too happy having this dependency because the name "nextTick" didn't ring a bell to most RxPlayer developers who never really worked with node.JS before, whereas the "microtask" concept is generally more known and understood in JavaScript environments, or at least is easier to look for on the internet.

Moreover, now that we consider that a Promise object has to be accessible globally in the current environment as a precondition to run the RxPlayer (so IE11 is now only supported as long as Promise is polyfilled by the application, which almost everyone still supporting that target in a complex media application does anyway) and that specification-following Promise implementations include a mean to schedule microtasks, we have a very easy way to provide a shim in cases where the queueMicroTask global function is not already supported.

So this commit removes the next-tick dependency and replace it by either the natively-provided queueMicroTask function or a Promise-based ponyfill if not, naming the result queueMicroTask, which should be much more familiar to JS dev and is a simpler implementation than what next-tick provided, we moreover now control.

Its removal also means that now the RxPlayer has no dependency from an application perspective, which may eliminates some groups of issues applications sometimes have when doing weird things with their webpack/vite configs :p

We may still have an issue for Promise implementations which do not rely on microtasks (or even event loop events, we shouldn't have an issue with those), but I would expect that the very large majority of Promise polyfills in use today respect that key part of the spec.

@peaBerberian peaBerberian added the Priority: 3 (Low) This issue or PR has a low priority. label Nov 8, 2023
For years, we had a unique external dependency (the only non-dev
dependency) called "next-tick" allowing us to schedule callbacks in
micro-tasks, either to provide asynchronous browser API shims or for
some specific logic where we would prefer to bring some asynchronicity
in without the need of bringing the event loop into this.

We were not too happy having this dependency because the name "nextTick"
didn't ring a bell to most RxPlayer developers who never really worked
with node.JS before, whereas the "microtask" concept is generally more
known and understood in JavaScript environments, or at least is easier
to look for on the internet.

Moreover, now that we consider that a Promise object has to be
accessible globally in the current environment as a precondition to run
the RxPlayer (so IE11 is now only supported as long as `Promise` is
polyfilled by the application, which almost everyone still
supporting that target in a complex media application does anyway) and
that specification-following Promise implementations include a mean
to schedule microtasks, we have a very easy way to provide a shim in
cases where the `queueMicroTask` global function is not already
supported.

So this commit removes the next-tick dependency and replace it by either
the natively-provided `queueMicroTask` function or a Promise-based
ponyfill if not, naming the result `queueMicroTask`, which should be
much more familiar to JS dev and is a simpler implementation than what
`next-tick` provided, we moreover now control.

Its removal also means that now the RxPlayer has no dependency from
an application perspective, which may eliminates some groups of issues
applications sometimes have when doing weird things with their
webpack/vite configs :p

We may still have an issue for Promise implementations which do not
rely on microtasks (or even event loop events, we shouldn't have an
issue with those), but I would expect that the very large majority of
Promise polyfills in use today respect that key part of the spec.
@peaBerberian peaBerberian force-pushed the misc/remove-next-tick-dependency branch from d77a736 to 6443b1d Compare November 13, 2023 15:21
@peaBerberian peaBerberian merged commit d4500be into next-v4 Nov 14, 2023
3 checks passed
@peaBerberian peaBerberian added this to the 4.0.0-rc.1 milestone Nov 14, 2023
peaBerberian added a commit that referenced this pull request Nov 14, 2023
peaBerberian added a commit that referenced this pull request Nov 14, 2023
peaBerberian added a commit that referenced this pull request Nov 23, 2023
peaBerberian added a commit that referenced this pull request Dec 4, 2023
peaBerberian added a commit that referenced this pull request Dec 5, 2023
peaBerberian added a commit that referenced this pull request Dec 5, 2023
peaBerberian added a commit that referenced this pull request Dec 7, 2023
peaBerberian added a commit that referenced this pull request Dec 19, 2023
peaBerberian added a commit that referenced this pull request Dec 20, 2023
peaBerberian added a commit that referenced this pull request Dec 22, 2023
peaBerberian added a commit that referenced this pull request Jan 3, 2024
peaBerberian added a commit that referenced this pull request Jan 3, 2024
@peaBerberian peaBerberian deleted the misc/remove-next-tick-dependency branch January 5, 2024 13:57
@peaBerberian peaBerberian restored the misc/remove-next-tick-dependency branch January 5, 2024 13:57
peaBerberian added a commit that referenced this pull request Jan 11, 2024
peaBerberian added a commit that referenced this pull request Jan 11, 2024
peaBerberian added a commit that referenced this pull request Jan 15, 2024
peaBerberian added a commit that referenced this pull request Jan 23, 2024
@peaBerberian peaBerberian mentioned this pull request Jan 24, 2024
@peaBerberian peaBerberian deleted the misc/remove-next-tick-dependency branch February 7, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 3 (Low) This issue or PR has a low priority.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants