Skip to content

Commit abbdb2c

Browse files
authored
Adds test for bugfix
1 parent ce4f338 commit abbdb2c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "https://esm.sh/react@19.0"
2+
import ReactDOM from "https://esm.sh/react-dom@19.0/client"
3+
import {Container} from "https://esm.sh/react-bootstrap@2.10.10/?deps=react@19.0,react-dom@19.0,react-is@19.0&exports=Container";
4+
export {Container};
5+
6+
export function bind(node, config) {
7+
const root = ReactDOM.createRoot(node);
8+
return {
9+
create: (type, props, children) =>
10+
React.createElement(type, props, children),
11+
render: (element) => root.render(element, node),
12+
unmount: () => root.unmount()
13+
};
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "https://esm.sh/react@19.0"
2+
import ReactDOM from "https://esm.sh/react-dom@19.0/client"
3+
import {Container} from "https://esm.sh/react-bootstrap@2.10.10/?deps=react@19.0,react-dom@19.0,react-is@19.0&exports=Container";
4+
export {Container};
5+
6+
export function bind(node, config) {
7+
const root = ReactDOM.createRoot(node);
8+
return {
9+
create: (type, props, children) =>
10+
React.createElement(type, props, children),
11+
render: (element) => root.render(element, node),
12+
unmount: () => root.unmount()
13+
};
14+
}

tests/test_web/test_module.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,32 @@ async def test_module_without_bind(display: DisplayFixture):
563563
"#my-generic-component", state="attached"
564564
)
565565
assert await element.inner_text() == "Hello World"
566+
567+
async def test_nest_custom_component_under_web_component(display: DisplayFixture):
568+
"""
569+
Fix https://github.com/reactive-python/reactpy/discussions/1323
570+
571+
Custom components (i.e those wrapped in the component decorator) were not able to
572+
be nested under web components.
573+
574+
"""
575+
module = reactpy.reactjs.file_to_module(
576+
"nest-custom-under-web", JS_FIXTURES_DIR / "nest-custom-under-web.js"
577+
)
578+
Container = reactpy.reactjs.module_to_vdom(module, "Container")
579+
580+
@reactpy.component
581+
def CustomComponent():
582+
return reactpy.html.div(
583+
reactpy.html.h1({"id": "my-header"}, "Header 1")
584+
)
585+
await display.show(
586+
lambda: Container(
587+
CustomComponent()
588+
)
589+
)
590+
591+
element = await display.page.wait_for_selector(
592+
"#my-header", state="attached"
593+
)
594+
assert await element.inner_text() == "Header 1"

0 commit comments

Comments
 (0)