Skip to content

Commit

Permalink
Fixed e2e test selector regression
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Sep 8, 2023
1 parent 5ac37f2 commit 697edd0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/replay-next/components/windowing/GenericList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ComponentType,
ReactElement,
useEffect,
useLayoutEffect,
useRef,
useState,
useSyncExternalStore,
Expand Down Expand Up @@ -101,19 +102,27 @@ export function GenericList<Item, ItemData extends Object>({
}
}, [itemCount, selectedItemIndex]);

useEffect(() => {
useLayoutEffect(() => {
// react-window doesn't provide a way to declaratively set data-* attributes
// but they're very useful for our e2e tests
// We use an effect without dependencies to set these so that we'll always (re)set them after a render,
// even if the name/id values haven't changed,
// so that other declarative updates don't erase these values
const element = outerRef.current;
if (element) {
if (dataTestId) {
element.setAttribute("data-test-id", dataTestId);
} else {
element.removeAttribute("data-test-id");
}

if (dataTestName) {
element.setAttribute("data-test-name", dataTestName);
} else {
element.removeAttribute("data-test-name");
}
}
}, [dataTestId, dataTestName]);
});

const internalItemData = {
itemData,
Expand Down

0 comments on commit 697edd0

Please sign in to comment.