@ripple-ts/compat-react 0.2.166 → 0.2.167

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ripple-ts/compat-react",
3
- "version": "0.2.166",
3
+ "version": "0.2.167",
4
4
  "description": "Ripple compatibility layer for React",
5
5
  "main": "src/index.js",
6
6
  "author": "Dominic Gannaway",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "react": "^19.2.0",
19
19
  "react-dom": "^19.2.0",
20
- "ripple": "0.2.166"
20
+ "ripple": "0.2.167"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^19.2.2",
@@ -1,5 +1,6 @@
1
1
  import { track, flushSync } from 'ripple';
2
- import { act } from 'react';
2
+ import { act, createContext, useContext } from 'react';
3
+ import { Ripple } from '@ripple-ts/compat-react';
3
4
 
4
5
  describe('compat-react', () => {
5
6
  it('should render basic React JSX inside tsx:react tags', async () => {
@@ -7,9 +8,7 @@ describe('compat-react', () => {
7
8
  <div>
8
9
  <h1>{'Hello from Ripple'}</h1>
9
10
  <tsx:react>
10
- <div className="react-content">
11
- {'Hello from React'}
12
- </div>
11
+ <div className="react-content">Hello from React</div>
13
12
  </tsx:react>
14
13
  </div>
15
14
  }
@@ -31,12 +30,8 @@ describe('compat-react', () => {
31
30
  <div>
32
31
  <tsx:react>
33
32
  <>
34
- <span className="first">
35
- {'First'}
36
- </span>
37
- <span className="second">
38
- {'Second'}
39
- </span>
33
+ <span className="first">First</span>
34
+ <span className="second">Second</span>
40
35
  </>
41
36
  </tsx:react>
42
37
  </div>
@@ -60,9 +55,7 @@ describe('compat-react', () => {
60
55
  <tsx:react>
61
56
  <div className="wrapper">
62
57
  <div className="inner">
63
- <span className="content">
64
- {'Nested content'}
65
- </span>
58
+ <span className="content">Nested content</span>
66
59
  </div>
67
60
  </div>
68
61
  </tsx:react>
@@ -87,9 +80,7 @@ describe('compat-react', () => {
87
80
  <div class="container">
88
81
  <div class="ripple">{'This is Ripple'}</div>
89
82
  <tsx:react>
90
- <div className="react">
91
- {'This is React'}
92
- </div>
83
+ <div className="react">This is React</div>
93
84
  </tsx:react>
94
85
  <div class="ripple-2">{'Back to Ripple'}</div>
95
86
  </div>
@@ -114,15 +105,11 @@ describe('compat-react', () => {
114
105
  component App() {
115
106
  <div>
116
107
  <tsx:react>
117
- <div className="react-1">
118
- {'React Block 1'}
119
- </div>
108
+ <div className="react-1">React Block 1</div>
120
109
  </tsx:react>
121
110
  <div class="ripple-middle">{'Ripple in between'}</div>
122
111
  <tsx:react>
123
- <div className="react-2">
124
- {'React Block 2'}
125
- </div>
112
+ <div className="react-2">React Block 2</div>
126
113
  </tsx:react>
127
114
  </div>
128
115
  }
@@ -147,9 +134,7 @@ describe('compat-react', () => {
147
134
  <div>
148
135
  <tsx:react>
149
136
  <div className="react" id="test-id">
150
- <span>
151
- {'Content'}
152
- </span>
137
+ <span>Content</span>
153
138
  </div>
154
139
  </tsx:react>
155
140
  </div>
@@ -170,13 +155,9 @@ describe('compat-react', () => {
170
155
  <div>
171
156
  <tsx:react>
172
157
  <>
173
- <div className="outer">
174
- {'Outer'}
175
- </div>
158
+ <div className="outer">Outer</div>
176
159
  <>
177
- <div className="inner">
178
- {'Inner'}
179
- </div>
160
+ <div className="inner">Inner</div>
180
161
  </>
181
162
  </>
182
163
  </tsx:react>
@@ -201,15 +182,9 @@ describe('compat-react', () => {
201
182
  <tsx:react>
202
183
  <div className="list">
203
184
  <ul>
204
- <li>
205
- {'Item 1'}
206
- </li>
207
- <li>
208
- {'Item 2'}
209
- </li>
210
- <li>
211
- {'Item 3'}
212
- </li>
185
+ <li>Item 1</li>
186
+ <li>Item 2</li>
187
+ <li>Item 3</li>
213
188
  </ul>
214
189
  </div>
215
190
  </tsx:react>
@@ -301,4 +276,88 @@ describe('compat-react', () => {
301
276
  expect(reactContent).toBeTruthy();
302
277
  expect(reactContent.textContent).toBe('This is rendered from a React component!');
303
278
  });
279
+
280
+ it('should handle a React context propagation', async () => {
281
+ const SomeContext = createContext('Default Value');
282
+
283
+ function ReactChild() {
284
+ return useContext(SomeContext);
285
+ }
286
+
287
+ component App() {
288
+ <div>
289
+ <tsx:react>
290
+ <SomeContext.Provider value="Provided Value">
291
+ <ReactChild />
292
+ </SomeContext.Provider>
293
+ </tsx:react>
294
+ </div>
295
+ }
296
+
297
+ await act(async () => {
298
+ render(App);
299
+ });
300
+
301
+ const reactContent = container.querySelector('div > div');
302
+ expect(reactContent).toBeTruthy();
303
+ expect(reactContent.textContent).toBe('Provided Value');
304
+ });
305
+
306
+ it('should handle a React errors', async () => {
307
+ function ReactChild() {
308
+ throw new Error('Test Error');
309
+ }
310
+
311
+ component App() {
312
+ try {
313
+ <div>
314
+ <tsx:react>
315
+ <ReactChild />
316
+ </tsx:react>
317
+ </div>
318
+ } catch (e) {
319
+ <div class="error">{'ReactChiild had an error'}</div>
320
+ }
321
+ }
322
+
323
+ await act(async () => {
324
+ render(App);
325
+ });
326
+
327
+ const reactContent = container.querySelector('div > div');
328
+ expect(reactContent).toBeTruthy();
329
+ expect(reactContent.textContent).toBe('ReactChiild had an error');
330
+ });
331
+
332
+ it('should handle a React errors #2', async () => {
333
+ function ReactChild() {
334
+ throw new Error('Test Error');
335
+ }
336
+
337
+ component RippleChild() {
338
+ <tsx:react>
339
+ <ReactChild />
340
+ </tsx:react>
341
+ }
342
+
343
+ component App() {
344
+ try {
345
+ <div>
346
+ <tsx:react>
347
+ <Ripple component={RippleChild} />
348
+ </tsx:react>
349
+ </div>
350
+ } catch (e) {
351
+ <div class="error">{'ReactChiild had an error'}</div>
352
+ }
353
+ }
354
+
355
+ await act(async () => {
356
+ render(App);
357
+ });
358
+
359
+ const reactContent = container.querySelector('div > div');
360
+ expect(reactContent).toBeTruthy();
361
+ expect(reactContent.textContent).toBe('ReactChiild had an error');
362
+ });
304
363
  });
package/tests/setup.js CHANGED
@@ -1,7 +1,14 @@
1
- import { beforeEach, afterEach } from 'vitest';
1
+ import { beforeEach, afterEach, vi } from 'vitest';
2
2
  import { mount } from 'ripple';
3
3
  import { createReactCompat } from '../src/index.js';
4
4
 
5
+ // Configure React testing environment for act() support
6
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
7
+
8
+ // Suppress React error/warning logs during tests
9
+ vi.spyOn(console, 'error').mockImplementation(() => {});
10
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
11
+
5
12
  /**
6
13
  * @param {() => void} component
7
14
  */