Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/react-intersection-observer/src/InView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class InView extends React.Component<
prevProps.scrollMargin !== this.props.scrollMargin ||
prevProps.root !== this.props.root ||
prevProps.threshold !== this.props.threshold ||
prevProps.triggerOnce !== this.props.triggerOnce ||
prevProps.skip !== this.props.skip ||
prevProps.trackVisibility !== this.props.trackVisibility ||
prevProps.delay !== this.props.delay
Expand Down
28 changes: 28 additions & 0 deletions packages/react-intersection-observer/src/__tests__/InView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ test("Should unobserve when triggerOnce comes into view", () => {
expect(instance.unobserve).toHaveBeenCalled();
});

test("Should resume observing when triggerOnce is disabled", () => {
const callback = vi.fn();
const { rerender } = render(
<InView triggerOnce onChange={callback}>
Inner
</InView>,
);

mockAllIsIntersecting(true);
expect(callback).toHaveBeenLastCalledWith(
true,
expect.objectContaining({ isIntersecting: true }),
);

rerender(
<InView triggerOnce={false} onChange={callback}>
Inner
</InView>,
);
callback.mockClear();
mockAllIsIntersecting(false);

expect(callback).toHaveBeenLastCalledWith(
false,
expect.objectContaining({ isIntersecting: false }),
);
});

test("Should unobserve when unmounted", () => {
const { container, unmount } = render(<InView triggerOnce>Inner</InView>);
const instance = intersectionMockInstance(container.children[0]);
Expand Down