RoamJS / roamjs-components

MIT License
15 stars 5 forks source link

ComponentContainer unmounts if parent added to tree #27

Closed mdroidian closed 5 months ago

mdroidian commented 5 months ago

EDIT: more specifically: when a preceding sibling is added to an ancestor block

Example https://www.loom.com/share/af9dce45fe654b96a56aacb9ee5d60d0

It looks like the cause is n.contains(p) from renderWithUnmount

const parentRemoved = ms
      .flatMap((m) => Array.from(m.removedNodes))
      .some((n) => n === p || n.contains(p));
    if (parentRemoved) {
      unmount(observer);
    }

@dvargas92495 , what case is n.contains(p) solving for that n === p doesn't?

EDIT: further testing showed that n.contains(p) is used when a block is being edited or folded

mdroidian commented 5 months ago

renderWithUnmount is directly used in

image

mdroidian commented 5 months ago

@dvargas92495 when a ComponentContainer goes from rendered React Component to edit block node, how is the node's previous content (the node's :block/string) being applied? Is Roam handling that? If we are, I haven't been able to find where we are doing that.

Example for query builder ResultsView

we call window.roamAlphaAPI.ui.setBlockFocusAndSelection and the observer gets unmounted.

                    <MenuItem
                      icon={"edit"}
                      text={"Edit Block"}
                      onClick={() => {
                        const location = getUids(
                          containerRef.current?.closest(
                            ".roam-block"
                          ) as HTMLDivElement
                        );
                        window.roamAlphaAPI.ui.setBlockFocusAndSelection({
                          location: {
                            "window-id": location.windowId,
                            "block-uid": location.blockUid,
                          },
                        });
                      }}
                    />
                  )}
mdroidian commented 5 months ago

Sorry, I think you can ignore that last question. I believe I found a different solution.