Skip to content

replace immediate with queueMicrotask#8849

Merged
garethbowen merged 27 commits intoapache:masterfrom
SourceR85:drop-immediate
Jan 31, 2024
Merged

replace immediate with queueMicrotask#8849
garethbowen merged 27 commits intoapache:masterfrom
SourceR85:drop-immediate

Conversation

@SourceR85
Copy link
Contributor

@SourceR85 SourceR85 commented Jan 23, 2024

This PR unifies pouchdb-utils/src/nextTick and pouchdb-utils/src/nextTick-browser by replacing the dependency on immediate and node-specific process.nextTick with standardised queueMicrotask-API.

Since the queueMicrotask-API has been standardized and established (see compatibility list at mdn), the immediate package is obsolete.

As mentioned in #8816 (comment)

hzd-lange and others added 2 commits January 23, 2024 16:03
This PR unifies pouchdb-utils/src/nextTick and pouchdb-utils/src/nextTick-browser,
also it reduces the callstack of pouchdb-utils/src/nextTick.
@SourceR85 SourceR85 changed the title Drop immediate drop immediate dependency Jan 23, 2024
@SourceR85
Copy link
Contributor Author

SourceR85 commented Jan 23, 2024

IMO: ready to merge.
I'm just re-execute the CI-Pipeline from now on (as usual, randomly failing tests: "test.sync.js" and "test.issue3179.js").

@SourceR85 SourceR85 changed the title drop immediate dependency replace immediate with queueMicrotask Jan 26, 2024
@SourceR85
Copy link
Contributor Author

SourceR85 commented Jan 29, 2024

Are you OK with this change @garethbowen?

@garethbowen
Copy link
Contributor

Honestly I'm a little reluctant. I think it raises the bar on browser support above where it currently is which always gives me pause. Otherwise as far as I can tell it's better in every way. How do you feel about keeping the next tick files around and updating the browser one to use queue microtask but falling back to a polyfill if it doesn't exist?

eg:

if (typeof queueMicrotask !== 'undefined') {
  queueMicrotask(fn);
} else {
  Promise.resolve().then(fn)
}

Alternatively if you can show Pouch already doesn't support Chrome 71 then it's fine as is...

@SourceR85
Copy link
Contributor Author

SourceR85 commented Jan 30, 2024

How do you feel about keeping the next tick files around

The Node docs specifies: nextTick, promise, and microTask queues are executed, in this order, at the end of each event loop and they seem to be equally optimized.
I don't see good reasons to keep them separated (as browser and node version) and it didn't affect the program flow of PouchDB.
This way, it feels even better: one less branch of behaviour (node vs browser) and one less non-standardized API.

use queue microtask but falling back to a polyfill if it doesn't exist?

Ok, done with the newest commit (pass ✅ at first try 🎉)

Alternatively if you can show Pouch already doesn't support Chrome 71 then it's fine as is...

Nothing more advanced than async/await (available since Chrome v55).

TBH I don't feel comfortable supporting (or enable people to keep) unmaintained versions of Chrome, 'cause PouchDB enables the execution of arbitrary code (views map & reduce functions) and the list of Chrome CVE's show some serious problems within the last years.

@garethbowen
Copy link
Contributor

TBH I don't feel comfortable supporting (or enable people to keep) unmaintained versions of Chrome

I agree in general, but if we drop support for browsers then we should probably bump the major version to make it clear, and notify everyone. We should definitely decide what our policy is and document that somewhere when we publish the next major version. Thanks for taking the time to make this backwards compatible for now!

Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

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

Thanks!

@garethbowen garethbowen merged commit 7278ae4 into apache:master Jan 31, 2024
@garethbowen
Copy link
Contributor

@SourceR85 Merged.

Does this mean we can close #8816 and linked issues? Have you tested that this solves the Vite and Nuxt issues?

@SourceR85 SourceR85 deleted the drop-immediate branch January 31, 2024 13:11
@SourceR85
Copy link
Contributor Author

SourceR85 commented Jan 31, 2024

Merged.

Thank you

Does this mean we can close #8816 and linked issues? Have you tested that this solves the Vite and Nuxt issues?

I don't see problems with Vite.js.
Totally forgotten to mentioned that: I have a customized and heavily stripped down copy of PouchDB in one of my production environments, I've replaced immediate with queueMicrotask back in Feb. 2022.
Reason for this was that the build pipeline (svelte compiled with rollup back than) had problems with immediate too.
When Svelte switched to Vite.js, the problem never shown up, because I already fixed it.

At least the Vite case, I can say: it is battle-tested and will be fine.
For the Nuxt case, only immediate was mentioned in the original post...
So, I don't see a reason why this patch shouldn't fix that specific issue (without a demo/repl: unconfirmable).

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.

3 participants