toeverything / blocksuite

🧩 Content editing tech stack for the web - BlockSuite is a toolkit for building editors and collaborative applications.
https://blocksuite.io
Mozilla Public License 2.0
4.53k stars 417 forks source link

[bug] [edgeless] Changing text in shapes does not render in other tab by sync #7257

Open RubaXa opened 5 months ago

RubaXa commented 5 months ago

Currently, rendering occurs when the model is changed, specifically when

However, there is no reaction to text changes, so when modifying text inside the shape, the render in the second tab will happen only on the next model element change.

RubaXa commented 4 months ago

@doodlewind any news?

doodlewind commented 4 months ago

@RubaXa thanks for the feedback! It's reproduced and I believe we'll land refactoring on edgeless data flow that fixes this together in this iteration. /cc @doouding

oliseviche commented 4 months ago

To be noted: It seems that everything should work out from the box initially, because @yfield decorator already contains the code block to run refresh on Y props changes, because it contains the call to startObserve(prototype, prop as string, this); method.

But, this flow is broken inside observer itself, because if no observer function provided, observer just quits here @blocksuite/blocks/src/surface-block/element-model/decorators/observer.ts

...
if (!observeFn) {
    return;
}
...

and by default it is not provided anywhere at @yfield declaration

F4lkr4m commented 3 weeks ago

That's right, it works almost out of the box. The problem is in the syncElementFromY (onElementChange in previous ver)

There is a subscription to change Y.Map fields, but not nested fields. Y.Text is already a nested field, so its events are ignored, which does not lead to an update trigger between clients.

To solve this problem, you need to change .observe to .observeDeep and support changes to all nested fields in the element model.

image