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

fix(flow-react): avoid Flow-React portal outlet removal conflicts #20770

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import {
type Dispatch,
type ReactElement,
type ReactNode,
Ref,
useEffect,
useReducer,
useRef
} from "react";

type FlowStateKeyChangedAction<K extends string, V> = Readonly<{
Expand Down Expand Up @@ -137,7 +135,7 @@ export abstract class ReactAdapterElement extends HTMLElement {

readonly #Wrapper: () => ReactElement | null;

#unmountComplete = Promise.resolve();
#unmounting = Promise.resolve();

constructor() {
super();
Expand All @@ -151,7 +149,6 @@ export abstract class ReactAdapterElement extends HTMLElement {
}

public async connectedCallback() {
await this.#unmountComplete;
this.#rendering = createElement(this.#Wrapper);
const createNewRoot = this.dispatchEvent(new CustomEvent('flow-portal-add', {
bubbles: true,
Expand All @@ -167,6 +164,8 @@ export abstract class ReactAdapterElement extends HTMLElement {
return;
}

await this.#unmounting;

this.#root = createRoot(this);
this.#maybeRenderRoot();
this.#root.render(this.#rendering);
Expand All @@ -187,19 +186,24 @@ export abstract class ReactAdapterElement extends HTMLElement {
}

public async disconnectedCallback() {
this.dispatchEvent(new CustomEvent('flow-portal-remove', {
bubbles: true,
cancelable: true,
composed: true,
detail: {
children: this.#rendering,
domNode: this,
}
}));
this.#unmountComplete = Promise.resolve();
await this.#unmountComplete;
this.#root?.unmount();
this.#root = undefined;
if (!this.#root) {
this.dispatchEvent(new CustomEvent('flow-portal-remove', {
bubbles: true,
cancelable: true,
composed: true,
detail: {
children: this.#rendering,
domNode: this,
}
}));
} else {
this.#unmounting = Promise.resolve();
await this.#unmounting;

this.#root?.unmount();
this.#root = undefined;
}

this.#rootRendered = false;
this.#rendering = undefined;
}
Expand Down
Loading
Loading