Skip to content
Closed
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
16 changes: 16 additions & 0 deletions packages/react-native-fantom/src/__tests__/Fantom-itest.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ describe('Fantom', () => {
},
);
});

it('throws when trying to render a root outside of a task', () => {
const root = Fantom.createRoot();

expect(() => {
root.render(<View />);
}).toThrow(
'Unexpected call to `render` outside of the event loop. Please call `render` within a `runTask` callback.',
);

expect(() => {
Fantom.runTask(() => {
root.render(<View />);
});
}).not.toThrow();
});
});

describe('getRenderedOutput', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/react-native-fantom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ class Root {
globalSurfaceIdCounter += 10;
}

render(element: MixedElement) {
render(element: MixedElement): void {
if (!flushingQueue) {
throw new Error(
'Unexpected call to `render` outside of the event loop. Please call `render` within a `runTask` callback.',
);
}

if (!this.#hasRendered) {
NativeFantom.startSurface(
this.#surfaceId,
Expand Down