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

Expose react reconciler #642

Merged
merged 1 commit into from
Mar 24, 2022
Merged

Conversation

tuoxiansp
Copy link
Contributor

@tuoxiansp tuoxiansp commented Jan 28, 2022

pmndrs/zustand#302 (comment)

Might be helpful with resolving zombie child problem.

I have deployed this modification to my app. neka.cc

It helps ensure some imperative code like node.cache() that was nested in useEffect to be executed in the same order that was declared by JSX.

@eXponenta
Copy link

eXponenta commented Mar 24, 2022

I want use it too, i want to use createPortal

@lavrton
Copy link
Member

lavrton commented Mar 24, 2022

Can someone give me an example why export reconciler is useful? How it is used in the code?

@eXponenta
Copy link

eXponenta commented Mar 24, 2022

Reconciller.render(node, location)
Reconciller.createPortal (node, location)

Strange question, there are a lot of usages of it.
Same as ReactDom used.

ReactDom is reconciler.

Atm we render isolated node as (render exposed from ReactDOM):
image

This is strange way, instead of this we can use a already exist Stage and render to it instead of div.

@lavrton
Copy link
Member

lavrton commented Mar 24, 2022

I just want to understand the real use case with react-konva and canvas components.

Created portal will be rendered into Konva.Container like Layer or Group? How will containers be created? How will app maintain it in the nodes tree?

I am ok to merge the PR. Just looking to edicate my self and understand how this can be used to create demos, docs.

@tuoxiansp
Copy link
Contributor Author

tuoxiansp commented Mar 24, 2022

My use case:

import { KonvaRenderer } from 'react-konva'
import { unstable_batchedUpdates } from 'react-dom'

unstable_batchedUpdates(() =>
  KonvaRenderer.batchedUpdates(() => {
    // updates
  }, null)
)

My problem is:
I'm using Filter to implement blend mode.

<Konva.Image /> // a
<Konva.Image /> // b
<Konva.Image filters={[BlendFilter]} /> // c

C will be updated after A or B updates and they should be updated in certain order.

Usually it's not a problem, cause React will batch updates nodes. But when I combine two react renderers, the one (ReactKonva) which was triggered update from outside data source, it's updates will not be batched performed.

In my case, it performs like this:
The update observers in state manager were in this order: [a, b, c].

When A node changes, observer a、b and c triggered update. React Konva performed three updates: first A then B then C.

Until now, everything went well .

Then something changed, cause some user's operation, the B node was replaced by D:

<Konva.Image /> // a
<Konva.Image /> // d -> new node here
<Konva.Image filters={[BlendFilter]} /> // c

In state manager, the new d observer was pushed into observer list, became: [a, c, d].

When A node changes, observer a、c and d were triggered. React Konva will perform three updates in an unexpected order: first A then C then D.

So, I need to get the react-konva-renderer instance to manually execute batchedUpdates function when data changes.

see: React 17 does NOT batch outside event handlers

Sorry for my poor English, did my best :p

@eXponenta
Copy link

Created portal will be rendered into Konva.Container like Layer or Group? How will containers be created? How will app maintain it in the nodes tree?

I have complex App, where ingame UI created in react-konva and binded as layers for WebXR layers.

Our fronts create a dom-like api bassed ot konva elements as separated libs.
Now we have rig:

react-dom for regula html app
react-ogl for 3D content
react-konva as ingame ui content

propblem that we should have a more plain tree for developing propose, and i want to use portals for attach nodes of React-konva outside.

Tree will be:


<Html>
     <Node3D>
           <KonvaPortal target={target.current}>
                  <Layer>
                        <Circle/>
                  </Layer>
           </KonvaPortal>
     </Node3D>

     <Stage ref={target}>
        ...
     </Stage>
</Html>

I can't said what is app by NDA until official announce.

@lavrton lavrton merged commit b5b223f into konvajs:master Mar 24, 2022
@lavrton
Copy link
Member

lavrton commented Mar 24, 2022

Published as [email protected].

@tuoxiansp for batching I hope react v18 will introduce many changes here. Currently, Konva events are not batched. v18 should resolve that.

@eXponenta that is very interesting. I will be REALLY good if you can create a very short sample with codesandbox that can demonstrate such use cases. It is interesting to see it in action.

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