visualknowledge 0.2.0 → 0.2.1

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.
@@ -5,6 +5,7 @@
5
5
  * 顶层聚合所有 Hooks,将数据通过 props 分发给子组件。
6
6
  */
7
7
 
8
+ import React from 'react';
8
9
  import { html } from 'htm/react';
9
10
  import { useAppState, ActionTypes } from './context/AppContext.jsx';
10
11
  import { TopBar } from './components/TopBar.jsx';
@@ -9,9 +9,55 @@ import { createRoot } from 'react-dom/client';
9
9
  import { App } from './App.jsx';
10
10
  import { AppProvider } from './context/AppContext.jsx';
11
11
 
12
+ // ====== Error Boundary ======
13
+
14
+ class ErrorBoundary extends React.Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = { error: null, errorInfo: null };
18
+ }
19
+ static getDerivedStateFromError(error) {
20
+ return { error };
21
+ }
22
+ componentDidCatch(error, errorInfo) {
23
+ console.error('[ErrorBoundary] React render error:', error, errorInfo);
24
+ this.setState({ error, errorInfo });
25
+ }
26
+ render() {
27
+ if (this.state.error) {
28
+ return React.createElement('div', {
29
+ style: {
30
+ padding: '24px', color: '#f87171', fontFamily: 'monospace',
31
+ fontSize: '14px', lineHeight: '1.6', whiteSpace: 'pre-wrap',
32
+ overflow: 'auto', height: '100vh', background: '#1c1917',
33
+ }
34
+ },
35
+ React.createElement('h2', null, 'React Rendering Error'),
36
+ React.createElement('p', null, this.state.error.toString()),
37
+ React.createElement('pre', null, this.state.errorInfo?.componentStack || ''),
38
+ );
39
+ }
40
+ return this.props.children;
41
+ }
42
+ }
43
+
44
+ // ====== Bootstrap ======
45
+
46
+ console.log('[main] Loading app...');
47
+
12
48
  const rootEl = document.getElementById('root');
13
49
  if (!rootEl) {
14
50
  throw new Error('Root element #root not found in DOM');
15
51
  }
16
52
 
17
- createRoot(rootEl).render(React.createElement(AppProvider, null, React.createElement(App)));
53
+ console.log('[main] Root element found, mounting React...');
54
+
55
+ createRoot(rootEl).render(
56
+ React.createElement(ErrorBoundary, null,
57
+ React.createElement(AppProvider, null,
58
+ React.createElement(App)
59
+ )
60
+ )
61
+ );
62
+
63
+ console.log('[main] App mounted successfully.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visualknowledge",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Interactive AI Chat with Visualization - one-click launch via npx",
5
5
  "bin": {
6
6
  "visualknowledge": "./bin/visualknowledge.js"
@@ -26,4 +26,4 @@
26
26
  "type": "git",
27
27
  "url": "https://github.com/user/VisualKnowledge"
28
28
  }
29
- }
29
+ }