Skip to content
Merged
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
18 changes: 5 additions & 13 deletions src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,29 +593,21 @@ export class ReactModel extends DOMWidgetModel {
);
module = await importShim(this.codeUrl);
if (!module) {
return () => <div>error loading module</div>;
throw new Error(`Error loading module`);
}
} else {
module = await importShim(moduleName);
if (!module) {
return () => <div>no module found with name {moduleName}</div>;
throw new Error(`no module found with name ${moduleName}`);
}
}
let component = module[type || "default"];
if (!component) {
if (type) {
return () => (
<div>
no component found in module {moduleName} (with name {type})
</div>
);
throw new Error(`no component ${type} found in module ${moduleName}`);
} else {
return () => (
<div>
no component found in module {moduleName} (it should be exported
as default)
</div>
);
throw new Error(`
no component found in module ${moduleName} (it should be exported as default)`);
}
} else {
if (this.compiledCode) {
Expand Down
31 changes: 31 additions & 0 deletions tests/ui/basics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,34 @@ def test_update_props_after_create(solara_test, page_session: playwright.sync_ap

display(b)
page_session.locator(".test-button-updated >> text=Button").wait_for()


def test_error_module(solara_test, page_session: playwright.sync_api.Page):
b = ipyreact.Widget(
_type="Foo",
_module="bar",
children=["should not be shown"],
)
display(b)
page_session.locator("text=Unable to resolve specifier").wait_for()


def test_error_type(solara_test, page_session: playwright.sync_api.Page):
ipyreact.define_module(
"my-module",
"""
import * as React from "react";

export function ClickButton({value, setValue}) {
return React.createElement("button", {
className: "counter-widget",
onClick: () => setValue(value + 1),
children: [`${value|| 0} clicks`],
})
};
""",
)

b = ipyreact.ValueWidget(_module="my-module", _type="ClickButtonMistyped")
display(b)
page_session.locator("text=no component ClickButtonMistyped found in module my-module").wait_for()
Loading