Skip to content

Commit 87036c2

Browse files
chrisgervangclaude
andcommitted
fix(react): Fix WebGL context exhaustion and nested act() errors in tests
- Reuse shared WebGL context from test-utils instead of creating new contexts to avoid "Too many active WebGL contexts" errors - Remove nested act() call in StrictMode test cleanup to avoid "Should not already be working" React scheduler errors Co-Authored-By: Claude (global.anthropic.claude-opus-4-5-20251101-v1:0) <noreply@anthropic.com>
1 parent bbe2b3b commit 87036c2

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

test/modules/react/deckgl.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const TEST_VIEW_STATE = {
2222
pitch: 45
2323
};
2424

25-
// If testing under node, provide a headless context
25+
// Reuse shared WebGL context from test-utils to avoid context exhaustion
26+
// gl is already set up by test-utils for both Node (headless) and browser
2627
/* global document */
27-
const getMockContext = () => (globalThis.__JSDOM__ ? gl : null);
28+
const getTestContext = () => gl;
2829

2930
test('DeckGL#mount/unmount', t => {
3031
const ref = createRef();
@@ -39,7 +40,7 @@ test('DeckGL#mount/unmount', t => {
3940
ref,
4041
width: 100,
4142
height: 100,
42-
gl: getMockContext(),
43+
gl: getTestContext(),
4344
onLoad: () => {
4445
const {deck} = ref.current;
4546
t.ok(deck, 'DeckGL is initialized');
@@ -72,7 +73,7 @@ test('DeckGL#render', t => {
7273
viewState: TEST_VIEW_STATE,
7374
width: 100,
7475
height: 100,
75-
gl: getMockContext(),
76+
gl: getTestContext(),
7677
onAfterRender: () => {
7778
const child = container.querySelector('.child');
7879
t.ok(child, 'Child is rendered');
@@ -122,7 +123,7 @@ test('DeckGL#props omitted are reset', t => {
122123
ref,
123124
width: 100,
124125
height: 100,
125-
gl: getMockContext(),
126+
gl: getTestContext(),
126127
layers: LAYERS,
127128
widgets: WIDGETS,
128129
onLoad: () => {
@@ -202,7 +203,7 @@ test('useWidget#StrictMode cleanup removes duplicate widgets', t => {
202203
ref,
203204
width: 100,
204205
height: 100,
205-
gl: getMockContext(),
206+
gl: getTestContext(),
206207
// Use onAfterRender instead of onLoad because React widget children
207208
// can only render after deck exists, and onLoad fires before that.
208209
// Widget children need multiple render cycles to be positioned and registered:
@@ -236,9 +237,8 @@ test('useWidget#StrictMode cleanup removes duplicate widgets', t => {
236237
t.ok(deck, 'DeckGL is initialized');
237238
t.is(widgets?.length, 1, 'Only one widget instance remains after StrictMode remount');
238239

239-
act(() => {
240-
root.render(null);
241-
});
240+
// Clean up - don't wrap in act() to avoid nested act() errors
241+
root.render(null);
242242
container.remove();
243243
t.end();
244244
}

0 commit comments

Comments
 (0)