Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Revert "Revert "descendants calc always lazy to ensure same order as …
Browse files Browse the repository at this point in the history
…before""

This reverts commit 418afdd.
  • Loading branch information
melnikov-s committed Apr 1, 2021
1 parent ccac700 commit 8453341
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 153 deletions.
3 changes: 0 additions & 3 deletions packages/react-testing/src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,11 @@ export class Element<Props> implements Node<Props> {
constructor(
private readonly tree: Tree<Props>,
private readonly allChildren: (Element<unknown> | string)[],
elementDescendants: Element<unknown>[] | null,
public readonly root: Root,
) {
this.elementChildren = allChildren.filter(
element => typeof element !== 'string',
) as Element<unknown>[];

this.descendantsCache = elementDescendants;
}

data(key: string): string | undefined {
Expand Down
13 changes: 3 additions & 10 deletions packages/react-testing/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ function defaultRender(element: React.ReactElement<unknown>) {
function fiberToElement(
element: Fiber,
root: Root<unknown>,
descendants = [],
rootLevel = true,
): Element<unknown> | string {
const node: Fiber = findCurrentFiberUsingSlowPath(element);

Expand All @@ -297,7 +295,7 @@ function fiberToElement(
}

const props = {...((node.memoizedProps as any) || {})};
const children = childrenToTree(node.child, root, descendants);
const children = childrenToTree(node.child, root);

return new Element(
{
Expand All @@ -307,22 +305,17 @@ function fiberToElement(
instance: node.stateNode,
},
children,
rootLevel ? descendants.reverse() : null,
root,
);
}

function childrenToTree(fiber: Fiber | null, root: Root<unknown>, descendants) {
function childrenToTree(fiber: Fiber | null, root: Root<unknown>) {
let currentFiber = fiber;
const children: (string | Element<unknown>)[] = [];

while (currentFiber != null) {
const result = fiberToElement(currentFiber, root, descendants, false);
const result = fiberToElement(currentFiber, root);
children.push(result);
if (typeof result !== 'string') {
descendants.push(result);
}

currentFiber = currentFiber.sibling;
}

Expand Down
Loading

0 comments on commit 8453341

Please sign in to comment.