cloneInstance fix: preserve children
This commit is contained in:
@@ -253,13 +253,18 @@ test("button onClick", async () => {
|
|||||||
test("button click with state", async () => {
|
test("button click with state", async () => {
|
||||||
function Counter() {
|
function Counter() {
|
||||||
const [count, setCount] = useState(0)
|
const [count, setCount] = useState(0)
|
||||||
return <Button onClick={() => setCount(count + 1)}>{count}</Button>
|
return (
|
||||||
|
<>
|
||||||
|
the count is {count}
|
||||||
|
<Button onClick={() => setCount(count + 1)}>increment</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertCount(count: number) {
|
async function assertCount(count: number) {
|
||||||
await assertMessages([
|
await assertMessages([
|
||||||
{
|
{
|
||||||
content: "_ _",
|
content: `the count is ${count}`,
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
type: "ACTION_ROW",
|
type: "ACTION_ROW",
|
||||||
@@ -267,7 +272,7 @@ test("button click with state", async () => {
|
|||||||
{
|
{
|
||||||
type: "BUTTON",
|
type: "BUTTON",
|
||||||
style: "SECONDARY",
|
style: "SECONDARY",
|
||||||
label: String(count),
|
label: "increment",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -89,7 +89,16 @@ export const reconciler = ReactReconciler<
|
|||||||
type: ElementTag,
|
type: ElementTag,
|
||||||
oldProps: Props,
|
oldProps: Props,
|
||||||
newProps: Props,
|
newProps: Props,
|
||||||
) => createInstance(type, newProps),
|
) => {
|
||||||
|
const newInstance = createInstance(type, newProps)
|
||||||
|
|
||||||
|
// instance children don't get carried over, so we need to copy them
|
||||||
|
if ("children" in instance && "children" in newInstance) {
|
||||||
|
newInstance.children = instance.children
|
||||||
|
}
|
||||||
|
|
||||||
|
return newInstance
|
||||||
|
},
|
||||||
|
|
||||||
// returning a non-null value tells react to re-render the whole thing
|
// returning a non-null value tells react to re-render the whole thing
|
||||||
// on any prop change
|
// on any prop change
|
||||||
|
|||||||
Reference in New Issue
Block a user