Skip to content

Commit 541bce0

Browse files
author
Beka Mekvabisvhili
committed
WIP: react 19 support
1 parent 3076888 commit 541bce0

4 files changed

Lines changed: 7351 additions & 5072 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
"@rollup/plugin-babel": "^6.0.3",
2222
"@rollup/plugin-commonjs": "^25.0.4",
2323
"@rollup/plugin-node-resolve": "^15.2.1",
24-
"@testing-library/react": "^14.0.0",
24+
"@testing-library/react": "^16.2.0",
2525
"@types/babel__code-frame": "^7.0.4",
2626
"@types/babel__core": "^7.20.2",
2727
"@types/babel__helper-plugin-utils": "^7.10.1",
2828
"@types/babel__traverse": "^7.20.2",
2929
"@types/node": "^20.7.0",
30-
"@types/react": "^18.2.23",
30+
"@types/react": "^19.0.10",
3131
"babel-plugin-tester": "^11.0.4",
3232
"esbuild": "0.19.3",
3333
"jsdom": "^22.1.0",
3434
"prettier": "3.0.3",
35-
"react": "^18.2.0",
36-
"react-dom": "^18.2.0",
35+
"react": "^19.0.0",
36+
"react-dom": "^19.0.0",
3737
"rollup": "^3.29.3",
3838
"rollup-plugin-typescript2": "^0.36.0",
3939
"tiny-glob": "^0.2.9",

packages/react-slots/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@
4444
"react-dom": {
4545
"optional": true
4646
}
47+
},
48+
"devDependencies": {
49+
"react": "^19.0.0",
50+
"react-dom": "^19.0.0"
4751
}
4852
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import * as React from "react";
2+
import { describe, it, expect, vi, beforeEach } from "vitest";
3+
import { render } from "@testing-library/react";
4+
import { template, useSlot, type SlotChildren } from "../src";
5+
6+
describe("Console warnings with React 19", () => {
7+
beforeEach(() => {
8+
// Spy on console methods
9+
vi.spyOn(console, "warn");
10+
vi.spyOn(console, "error");
11+
vi.spyOn(console, "log");
12+
});
13+
14+
it("should not log any warnings or errors when using default slots with various children configurations", () => {
15+
const TestComponent = (props: { children: SlotChildren }) => {
16+
const { slot } = useSlot(props.children);
17+
return <div>{slot.default()}</div>;
18+
};
19+
20+
// Test single child
21+
render(
22+
<TestComponent>
23+
<div>Test content</div>
24+
</TestComponent>,
25+
);
26+
27+
// Test multiple children
28+
render(
29+
<TestComponent>
30+
<div>Test content 1</div>
31+
<div>Test content 2</div>
32+
text node
33+
</TestComponent>,
34+
);
35+
36+
// Test single template
37+
render(
38+
<TestComponent>
39+
<template.default>
40+
<div>Template content</div>
41+
</template.default>
42+
</TestComponent>,
43+
);
44+
45+
// Test multiple templates with mixed content
46+
render(
47+
<TestComponent>
48+
<template.default>
49+
<div>Template 1</div>
50+
text node
51+
</template.default>
52+
<template.default>
53+
<div>Template 2</div>
54+
</template.default>
55+
<template.default>{() => <div>Template 3</div>}</template.default>
56+
{() => <div>Template 4</div>}
57+
</TestComponent>,
58+
);
59+
60+
// Check that no console methods were called across all renders
61+
expect(console.warn).not.toHaveBeenCalled();
62+
expect(console.error).not.toHaveBeenCalled();
63+
expect(console.log).not.toHaveBeenCalled();
64+
});
65+
66+
it("should not log any warnings or errors when using named slots with various configurations", () => {
67+
// Test component with optional and required named slots
68+
const TestComponent1 = (props: { children: SlotChildren }) => {
69+
const { slot, hasSlot } = useSlot(props.children);
70+
return (
71+
<div>
72+
{hasSlot.header && slot.header()}
73+
{slot.content()}
74+
{slot.footer?.()}
75+
</div>
76+
);
77+
};
78+
79+
// Test component with multiple instances of the same named slot
80+
const TestComponent2 = (props: { children: SlotChildren }) => {
81+
const { slot } = useSlot(props.children);
82+
return <div>{slot.foo()}</div>;
83+
};
84+
85+
// Test optional and required named slots
86+
render(
87+
<TestComponent1>
88+
<template.header>
89+
<div>Header</div>
90+
</template.header>
91+
<template.content>
92+
<div>Content</div>
93+
</template.content>
94+
</TestComponent1>,
95+
);
96+
97+
// Test multiple instances of the same named slot with mixed syntax
98+
render(
99+
<TestComponent2>
100+
<template.foo>
101+
<div>Foo Template 1</div>
102+
</template.foo>
103+
<template.foo>
104+
<div>Foo Template 2</div>
105+
</template.foo>
106+
<div slot-name="foo">Foo Direct</div>
107+
</TestComponent2>,
108+
);
109+
110+
// Check that no console methods were called across all renders
111+
expect(console.warn).not.toHaveBeenCalled();
112+
expect(console.error).not.toHaveBeenCalled();
113+
expect(console.log).not.toHaveBeenCalled();
114+
});
115+
});

0 commit comments

Comments
 (0)