Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/Portal/PortalHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export default class PortalHost extends React.Component<Props> {
const queue = this.queue;

while (queue.length && manager) {
const action = queue.pop();
// Replay in the order the operations were recorded, otherwise portals
// that mounted in the same commit end up stacked in reverse.
const action = queue.shift();
if (action) {
switch (action.type) {
case 'mount':
Expand Down
48 changes: 48 additions & 0 deletions src/components/__tests__/Portal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Text } from 'react-native';
import { expect, it, jest } from '@jest/globals';

import { render, screen } from '../../test-utils';
import Dialog from '../Dialog/Dialog';
import Modal from '../Modal';
import Portal from '../Portal/Portal';

jest.useRealTimers();
Expand All @@ -21,3 +23,49 @@ it('renders portal with siblings', async () => {

expect(toJSON()).toMatchSnapshot();
});

it('renders portals in source order when mounted in the same commit', async () => {
await render(
<Portal.Host>
<Portal>
<Text testID="portal-content">first</Text>
</Portal>
<Portal>
<Text testID="portal-content">second</Text>
</Portal>
<Portal>
<Text testID="portal-content">third</Text>
</Portal>
</Portal.Host>
);

const portals = await screen.findAllByTestId('portal-content');

expect(portals).toHaveLength(3);
expect(portals[0]).toHaveTextContent('first');
expect(portals[1]).toHaveTextContent('second');
expect(portals[2]).toHaveTextContent('third');
});

it('stacks components mounted in the same commit in source order', async () => {
await render(
<Portal.Host>
<Portal>
<Modal visible onDismiss={() => {}}>
<Text testID="layer">modal</Text>
</Modal>
</Portal>
<Portal>
<Dialog visible onDismiss={() => {}}>
<Text testID="layer">dialog</Text>
</Dialog>
</Portal>
</Portal.Host>
);

const layers = await screen.findAllByTestId('layer');

expect(layers).toHaveLength(2);
expect(layers[0]).toHaveTextContent('modal');
expect(layers[1]).toHaveTextContent('dialog');
});