Skip to content

Commit 088e10a

Browse files
authored
fix(example): remove unnecessary Vite workarounds from example app (#7)
The Vite hook deletion, manual WebSocket awaiting, and dynamic imports were not needed - the connection issues were caused by a separate bug. Simplify to the straightforward initialize() + connectToDevTools() flow.
1 parent 121ddba commit 088e10a

File tree

1 file changed

+8
-41
lines changed

1 file changed

+8
-41
lines changed

examples/react-app/src/main.tsx

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
import { initialize, connectToDevTools } from 'react-devtools-core';
22
import { StrictMode } from 'react';
3-
4-
// Vite's React Refresh preamble installs a minimal DevTools hook stub
5-
// that lacks rendererInterfaces and a proper inject(). Remove it so
6-
// initialize() can install the full hook from react-devtools-core.
7-
// This must happen before react-dom loads (hence the dynamic import below).
8-
try {
9-
delete (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__;
10-
} catch {
11-
// ignore — property may be non-configurable (browser extension)
12-
}
3+
import { createRoot } from 'react-dom/client';
4+
import App from './App';
135

146
initialize();
7+
connectToDevTools({ port: 8097 });
158

16-
async function main() {
17-
// Connect to the DevTools daemon and wait for the backend to
18-
// initialize before loading React. connectToDevTools sets ws.onopen
19-
// which runs initBackend (subscribes to hook operations). We must
20-
// wait for that before React renders, otherwise the first render's
21-
// operations are lost and the component tree appears empty.
22-
await new Promise<void>((resolve) => {
23-
try {
24-
const ws = new WebSocket('ws://localhost:8097');
25-
connectToDevTools({ port: 8097, websocket: ws });
26-
// addEventListener fires after the onopen property handler,
27-
// so initBackend has already run by the time we resolve.
28-
ws.addEventListener('open', () => resolve());
29-
ws.addEventListener('error', () => resolve());
30-
setTimeout(resolve, 2000); // don't block app if daemon isn't running
31-
} catch {
32-
resolve();
33-
}
34-
});
35-
36-
const { createRoot } = await import('react-dom/client');
37-
const { default: App } = await import('./App');
38-
39-
createRoot(document.getElementById('root')!).render(
40-
<StrictMode>
41-
<App />
42-
</StrictMode>,
43-
);
44-
}
45-
46-
main();
9+
createRoot(document.getElementById('root')!).render(
10+
<StrictMode>
11+
<App />
12+
</StrictMode>,
13+
);

0 commit comments

Comments
 (0)