@sigmaott/base-next 1.4.38 → 1.4.39
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 +1 -1
- package/src/composables/microState.ts +13 -4
- package/src/plugins/wujie.ts +62 -24
- package/src/utils/component-resolution.ts +66 -38
package/package.json
CHANGED
|
@@ -15,8 +15,17 @@ watch(microState, (newValue) => {
|
|
|
15
15
|
}, { deep: true })
|
|
16
16
|
|
|
17
17
|
export function syncMicroState() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
try {
|
|
19
|
+
if (typeof window !== 'undefined' && window.parent && window.parent.__SIGMA_STATE__) {
|
|
20
|
+
microState.value = klona(window.parent.__SIGMA_STATE__)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof window !== 'undefined' && window.$wujie?.bus) {
|
|
24
|
+
window.$wujie.bus.$on('__STATE_CHANGE__', (newState: any) => {
|
|
25
|
+
microState.value = klona(newState)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('[MicroState] Error syncing micro state:', error)
|
|
30
|
+
}
|
|
22
31
|
}
|
package/src/plugins/wujie.ts
CHANGED
|
@@ -1,32 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
// Type declarations for Wujie
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
__POWERED_BY_WUJIE__?: boolean
|
|
5
|
+
__WUJIE_MOUNT?: () => void
|
|
6
|
+
__WUJIE_UNMOUNT?: () => void
|
|
7
|
+
__WUJIE?: {
|
|
8
|
+
mount: () => void
|
|
9
|
+
id?: string
|
|
10
|
+
cleanup?: () => void
|
|
11
|
+
}
|
|
12
|
+
$wujie?: {
|
|
13
|
+
bus?: {
|
|
14
|
+
$on: (event: string, callback: (data: any) => void) => void
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
parent?: {
|
|
18
|
+
__SIGMA_STATE__?: any
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
2
22
|
|
|
3
23
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
-
//
|
|
5
|
-
|
|
24
|
+
// Ensure nuxtApp is properly initialized
|
|
25
|
+
if (!nuxtApp) {
|
|
26
|
+
console.warn('[Wujie] nuxtApp is not available')
|
|
27
|
+
return
|
|
28
|
+
}
|
|
6
29
|
|
|
7
30
|
nuxtApp.hook('app:created', async (app) => {
|
|
8
31
|
await new Promise<void>((resolve, reject) => {
|
|
9
32
|
if (window.__POWERED_BY_WUJIE__) {
|
|
10
33
|
window.__WUJIE_MOUNT = () => {
|
|
11
34
|
try {
|
|
12
|
-
|
|
35
|
+
// Simple sync without external dependencies
|
|
36
|
+
if (typeof window !== 'undefined' && window.parent && window.parent.__SIGMA_STATE__) {
|
|
37
|
+
console.log('[Wujie] Syncing micro state')
|
|
38
|
+
}
|
|
13
39
|
resolve()
|
|
14
40
|
} catch (error) {
|
|
15
41
|
console.error('[Wujie] Error during mount:', error)
|
|
16
|
-
if (isComponentResolutionError(error)) {
|
|
17
|
-
handleComponentResolutionError(error, 'wujie-mount')
|
|
18
|
-
}
|
|
19
42
|
reject(error)
|
|
20
43
|
}
|
|
21
44
|
}
|
|
22
45
|
window.__WUJIE_UNMOUNT = () => {
|
|
23
46
|
try {
|
|
24
|
-
app.unmount
|
|
47
|
+
if (app && typeof app.unmount === 'function') {
|
|
48
|
+
app.unmount()
|
|
49
|
+
}
|
|
25
50
|
} catch (error) {
|
|
26
51
|
console.error('[Wujie] Error during unmount:', error)
|
|
27
|
-
if (isComponentResolutionError(error)) {
|
|
28
|
-
handleComponentResolutionError(error, 'wujie-unmount')
|
|
29
|
-
}
|
|
30
52
|
}
|
|
31
53
|
}
|
|
32
54
|
|
|
@@ -37,14 +59,17 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
37
59
|
}, 5000)
|
|
38
60
|
|
|
39
61
|
try {
|
|
40
|
-
window.__WUJIE.mount
|
|
41
|
-
|
|
62
|
+
if (window.__WUJIE && typeof window.__WUJIE.mount === 'function') {
|
|
63
|
+
window.__WUJIE.mount()
|
|
64
|
+
clearTimeout(timeout)
|
|
65
|
+
} else {
|
|
66
|
+
console.warn('[Wujie] __WUJIE.mount is not available')
|
|
67
|
+
clearTimeout(timeout)
|
|
68
|
+
resolve()
|
|
69
|
+
}
|
|
42
70
|
} catch (error) {
|
|
43
71
|
clearTimeout(timeout)
|
|
44
72
|
console.error('[Wujie] Error mounting app:', error)
|
|
45
|
-
if (isComponentResolutionError(error)) {
|
|
46
|
-
handleComponentResolutionError(error, 'wujie-mount-init')
|
|
47
|
-
}
|
|
48
73
|
reject(error)
|
|
49
74
|
}
|
|
50
75
|
}
|
|
@@ -56,17 +81,30 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
56
81
|
|
|
57
82
|
// Enhanced error handling for component resolution
|
|
58
83
|
nuxtApp.hook('app:error', (error) => {
|
|
59
|
-
if (
|
|
60
|
-
|
|
84
|
+
if (error?.message?.includes('Couldn\'t resolve component')) {
|
|
85
|
+
console.warn('[Nuxt] Component resolution error detected:', error)
|
|
86
|
+
// Simple recovery - reload page after delay
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
89
|
+
window.location.reload()
|
|
90
|
+
}
|
|
91
|
+
}, 1000)
|
|
61
92
|
}
|
|
62
93
|
})
|
|
63
94
|
|
|
64
|
-
// Handle Vue component errors
|
|
65
|
-
nuxtApp.vueApp.config
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
95
|
+
// Handle Vue component errors - with safety check
|
|
96
|
+
if (nuxtApp.vueApp && nuxtApp.vueApp.config) {
|
|
97
|
+
nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
|
|
98
|
+
if (error?.message?.includes('Couldn\'t resolve component')) {
|
|
99
|
+
console.warn('[Vue] Component resolution error:', error)
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
102
|
+
window.location.reload()
|
|
103
|
+
}
|
|
104
|
+
}, 1000)
|
|
105
|
+
} else {
|
|
106
|
+
console.error('[Vue] Error:', error, 'Info:', info)
|
|
107
|
+
}
|
|
70
108
|
}
|
|
71
109
|
}
|
|
72
110
|
})
|
|
@@ -21,38 +21,53 @@ export function isComponentResolutionError(error: any): error is ComponentResolu
|
|
|
21
21
|
* Handles component resolution errors with recovery strategies
|
|
22
22
|
*/
|
|
23
23
|
export function handleComponentResolutionError(error: ComponentResolutionError, context: string = 'unknown') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Extract component name and path from error message
|
|
27
|
-
const componentMatch = error.message?.match(/component "([^"]+)"/)
|
|
28
|
-
const pathMatch = error.message?.match(/at "([^"]+)"/)
|
|
29
|
-
|
|
30
|
-
if (componentMatch) {
|
|
31
|
-
error.componentName = componentMatch[1]
|
|
32
|
-
}
|
|
33
|
-
if (pathMatch) {
|
|
34
|
-
error.path = pathMatch[1]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Determine if error is recoverable
|
|
38
|
-
error.isRecoverable = !error.message?.includes('permanent') &&
|
|
39
|
-
!error.message?.includes('fatal')
|
|
40
|
-
|
|
41
|
-
if (error.isRecoverable) {
|
|
42
|
-
console.log(`[${context}] Attempting recovery for component: ${error.componentName} at ${error.path}`)
|
|
24
|
+
try {
|
|
25
|
+
console.warn(`[${context}] Component resolution error detected:`, error)
|
|
43
26
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
// Ensure error has message property
|
|
28
|
+
if (!error || typeof error !== 'object') {
|
|
29
|
+
console.error(`[${context}] Invalid error object:`, error)
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Extract component name and path from error message
|
|
34
|
+
const componentMatch = error.message?.match(/component "([^"]+)"/)
|
|
35
|
+
const pathMatch = error.message?.match(/at "([^"]+)"/)
|
|
36
|
+
|
|
37
|
+
if (componentMatch) {
|
|
38
|
+
error.componentName = componentMatch[1]
|
|
39
|
+
}
|
|
40
|
+
if (pathMatch) {
|
|
41
|
+
error.path = pathMatch[1]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Determine if error is recoverable
|
|
45
|
+
error.isRecoverable = !error.message?.includes('permanent') &&
|
|
46
|
+
!error.message?.includes('fatal')
|
|
47
|
+
|
|
48
|
+
if (error.isRecoverable) {
|
|
49
|
+
console.log(`[${context}] Attempting recovery for component: ${error.componentName} at ${error.path}`)
|
|
50
|
+
|
|
51
|
+
// Strategy 1: Wait and retry - with safety check
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
try {
|
|
54
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
55
|
+
console.log(`[${context}] Reloading page for recovery...`)
|
|
56
|
+
window.location.reload()
|
|
57
|
+
}
|
|
58
|
+
} catch (reloadError) {
|
|
59
|
+
console.error(`[${context}] Error during page reload:`, reloadError)
|
|
60
|
+
}
|
|
61
|
+
}, 1000)
|
|
62
|
+
} else {
|
|
63
|
+
console.error(`[${context}] Non-recoverable component resolution error:`, error)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return error.isRecoverable
|
|
67
|
+
} catch (handlerError) {
|
|
68
|
+
console.error(`[${context}] Error in handleComponentResolutionError:`, handlerError)
|
|
69
|
+
return false
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
return error.isRecoverable
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
/**
|
|
@@ -135,21 +150,34 @@ export function createComponentResolutionChecker(
|
|
|
135
150
|
* Global error handler for component resolution issues
|
|
136
151
|
*/
|
|
137
152
|
export function setupGlobalComponentResolutionHandler() {
|
|
153
|
+
// Ensure we're in a browser environment
|
|
154
|
+
if (typeof window === 'undefined') {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
138
158
|
// Handle unhandled promise rejections
|
|
139
159
|
window.addEventListener('unhandledrejection', (event) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
160
|
+
try {
|
|
161
|
+
if (isComponentResolutionError(event.reason)) {
|
|
162
|
+
console.warn('[Global] Unhandled component resolution error:', event.reason)
|
|
163
|
+
handleComponentResolutionError(event.reason, 'global-unhandled')
|
|
164
|
+
event.preventDefault()
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('[Global] Error in unhandledrejection handler:', error)
|
|
144
168
|
}
|
|
145
169
|
})
|
|
146
170
|
|
|
147
171
|
// Handle general errors
|
|
148
172
|
window.addEventListener('error', (event) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
173
|
+
try {
|
|
174
|
+
if (isComponentResolutionError(event.error)) {
|
|
175
|
+
console.warn('[Global] Component resolution error:', event.error)
|
|
176
|
+
handleComponentResolutionError(event.error, 'global-error')
|
|
177
|
+
event.preventDefault()
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error('[Global] Error in error handler:', error)
|
|
153
181
|
}
|
|
154
182
|
})
|
|
155
183
|
}
|