Skip to content

Commit

Permalink
v11: Fix root order detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Nov 20, 2022
1 parent d79a862 commit 1947f76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/adapter/11/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getStatefulHooks,
getStatefulHookValue,
TYPE_COMPONENT,
isRoot,
} from "./bindings";
import { RendererConfig } from "../shared/renderer";
import { Renderer } from "../renderer";
Expand Down Expand Up @@ -87,6 +88,10 @@ function trackPrevState(Ctor: any) {
};
}

function getParentDom(internal: Internal): Node | null {
return internal.props?._parentDom || internal.props?.__P || null;
}

export function setupOptionsV11(
options: OptionsV11,
renderer: Renderer,
Expand Down Expand Up @@ -209,6 +214,12 @@ export function setupOptionsV11(

// These cases are already handled by `unmount`
if (internal == null) return;
if (isRoot(internal, config)) {
const dom = getParentDom(internal);
if (dom) {
roots.set(internal, dom);
}
}

renderer.onCommit(internal, owners, timings, renderReasons);

Expand Down
4 changes: 4 additions & 0 deletions test-e2e/tests/root-islands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test("Islands roots should be sorted by DOM order", async ({ page }) => {
});

test("Virtual island roots should be sorted by DOM order", async ({ page }) => {
test.skip(
process.env.PREACT_VERSION !== "10",
"Fake root DOM node is not supported in v11",
);
const { devtools } = await gotoTest(page, "islands-order-virtual");

const items = await getTreeItems(devtools);
Expand Down

0 comments on commit 1947f76

Please sign in to comment.