vaderjs-native 1.0.31 → 1.0.32

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.
@@ -22,7 +22,7 @@ To build and run on Android, you need the **Android SDK**:
22
22
  # Add to your .bashrc, .zshrc, or Windows ENV
23
23
  ANDROID_HOME=$HOME/Android/Sdk
24
24
  PATH=$PATH:$ANDROID_HOME/platform-tools
25
- ```
25
+
26
26
 
27
27
  ### 3. Windows Setup (Desktop)
28
28
 
@@ -208,4 +208,5 @@ VaderNative implements **Native Pipe & Log Tailing**.
208
208
  * **Hot Module Replacement:** Fast development with real-time updates
209
209
  * **Cross-Platform:** Build for web, Android, and Windows from the same codebase
210
210
 
211
-
211
+
212
+
package/index.ts CHANGED
@@ -27,6 +27,7 @@ if (typeof window !== 'undefined') {
27
27
  }
28
28
 
29
29
  // Error Boundary Component
30
+ // Error Boundary Component - FIXED VERSION
30
31
  export function ErrorBoundary({
31
32
  children,
32
33
  fallback,
@@ -35,6 +36,44 @@ export function ErrorBoundary({
35
36
  children: VNode | VNode[];
36
37
  fallback?: (error: Error, reset: () => void) => VNode;
37
38
  onError?: (error: Error, errorInfo: { componentStack: string }) => void;
39
+ }): VNode | null {
40
+ // We need to use try-catch because hooks can also throw errors
41
+ try {
42
+ // Move the hook calls into a separate component
43
+ return ErrorBoundaryInner({ children, fallback, onError });
44
+ } catch (error) {
45
+ // If hooks fail, render a simple fallback
46
+ const errorObj = error instanceof Error ? error : new Error(String(error));
47
+ if (fallback) {
48
+ return fallback(errorObj, () => window.location.reload());
49
+ }
50
+
51
+ return createElement(
52
+ "div",
53
+ {
54
+ style: {
55
+ padding: '20px',
56
+ backgroundColor: '#f8d7da',
57
+ color: '#721c24',
58
+ border: '1px solid #f5c6cb',
59
+ borderRadius: '5px'
60
+ }
61
+ },
62
+ createElement("h3", {}, "Error Boundary Failed"),
63
+ createElement("pre", { style: { whiteSpace: 'pre-wrap' } }, errorObj.toString())
64
+ );
65
+ }
66
+ }
67
+
68
+ // Inner component that uses hooks
69
+ function ErrorBoundaryInner({
70
+ children,
71
+ fallback,
72
+ onError
73
+ }: {
74
+ children: VNode | VNode[];
75
+ fallback?: (error: Error, reset: () => void) => VNode;
76
+ onError?: (error: Error, errorInfo: { componentStack: string }) => void;
38
77
  }): VNode | null {
39
78
  const [error, setError] = useState<Error | null>(null);
40
79
  const [errorInfo, setErrorInfo] = useState<{ componentStack: string } | null>(null);
@@ -44,21 +83,38 @@ export function ErrorBoundary({
44
83
  setErrorInfo(null);
45
84
  };
46
85
 
47
- // Listen for global errors
48
86
  useEffect(() => {
49
- const originalHandler = globalErrorHandler;
50
- globalErrorHandler = (error: Error, componentStack?: string) => {
51
- setError(error);
87
+ // Handle errors from children components
88
+ const handleError = (err: Error, componentStack?: string) => {
89
+ setError(err);
52
90
  if (componentStack) {
53
91
  setErrorInfo({ componentStack });
54
92
  }
55
93
  if (onError) {
56
- onError(error, { componentStack: componentStack || '' });
94
+ onError(err, { componentStack: componentStack || '' });
57
95
  }
58
96
  };
59
-
97
+
98
+ // Store the previous handler
99
+ const previousHandler = globalErrorHandler;
100
+ globalErrorHandler = handleError;
101
+
102
+ // Also catch unhandled errors and promise rejections
103
+ const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
104
+ handleError(event.reason, 'Unhandled Promise Rejection');
105
+ };
106
+
107
+ const handleUncaughtError = (event: ErrorEvent) => {
108
+ handleError(event.error, 'Uncaught Error');
109
+ };
110
+
111
+ window.addEventListener('unhandledrejection', handleUnhandledRejection);
112
+ window.addEventListener('error', handleUncaughtError);
113
+
60
114
  return () => {
61
- globalErrorHandler = originalHandler;
115
+ globalErrorHandler = previousHandler;
116
+ window.removeEventListener('unhandledrejection', handleUnhandledRejection);
117
+ window.removeEventListener('error', handleUncaughtError);
62
118
  };
63
119
  }, [onError]);
64
120
 
@@ -90,7 +146,7 @@ export function ErrorBoundary({
90
146
  color: '#ff6b6b',
91
147
  marginBottom: '20px',
92
148
  fontSize: '24px'
93
- } }, "⚠️ VaderJS Error"),
149
+ } }, "⚠️ Application Error"),
94
150
 
95
151
  createElement("div", { style: {
96
152
  backgroundColor: '#2a2a2a',
@@ -838,7 +894,7 @@ export function render(element: VNode, container: Node): void {
838
894
  wipRoot = {
839
895
  dom: container,
840
896
  props: {
841
- children: [element],
897
+ children: isDev ? [createElement(ErrorBoundary, {}, element)] : [element],
842
898
  },
843
899
  alternate: currentRoot,
844
900
  };
@@ -2237,10 +2293,4 @@ Object.defineProperty(window, "Vader", {
2237
2293
  configurable: false,
2238
2294
  });
2239
2295
 
2240
- if (isDev) {
2241
- const originalRender = Vader.render;
2242
- Vader.render = function(element: VNode, container: Node) {
2243
- // Wrap in error boundary in dev mode
2244
- renderWithErrorBoundary(element, container);
2245
- };
2246
- }
2296
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs-native",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "binaryVersion": "1.0.26",
5
5
  "description": "Build Native Applications using Vaderjs framework.",
6
6
  "bin": {