preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.65k stars 1.95k forks source link

Options debounceRendering and requestAnimationFrame #4434

Closed andywilsonuk closed 3 months ago

andywilsonuk commented 3 months ago

I'd like to check my understanding of these two option hooks.

What I'm trying to achieve is that preact is told explicitly when to render updates so that it does not use window.setTimeout nor window.requestAnimationFrame. I think the two options refer to different parts of preact and as such I need to queue up the callbacks for both and execute them during my "render" stage.

As an aside I'm mostly using Signals to push changes to preact and I'm not sure when those pushed updates are processed.

Having read the docs and looked at the code, I'm still not completely sure I understand so please could you tell me whether I've got it correct?

Cheers

JoviDeCroock commented 3 months ago

Hey,

Any full component update resulting from state setting in hooks, components or signals that aren't targeting text-nodes/DOM-attributes will be processed with options.debounceRendering. This by default will be a micro-tick, comparable to window.queueMicrotask. All optimised updates in signals are synchronous this means, computeds/effects/text-nodes/dom-attributes, when you i.e. use a signal to do some conditional Virtual DOM then it will fallback to the normal state-setting queueing.

The RAF timing that can be used with the automatic react-transform/... are something else, we also use RAF internally in hooks for i.e. effects.

I would encourage any signals specific question to be aimed at https://github.com/preactjs/signals/discussions