Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error when calling root.render outside of a task #49003

Closed
wants to merge 1 commit into from
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
Loading