@nine-lab/nine-mu 0.1.337 โ 0.1.339
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/dist/nine-mu.js +50 -31
- package/dist/nine-mu.js.map +1 -1
- package/dist/nine-mu.umd.js +3 -3
- package/dist/nine-mu.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/exception/ExceptionHook.js +54 -34
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// src/components/exception/ExceptionHook.js
|
|
2
|
+
import { nine } from '@nine-lab/nine-util';
|
|
3
|
+
|
|
2
4
|
export class ExceptionHook extends HTMLElement {
|
|
3
|
-
// ๐ก
|
|
5
|
+
// ๐ก ๋น๊ณต๊ฐ ์ธ์คํด์ค ํ๋ ์ ์
|
|
4
6
|
#lastPath = window.location.pathname;
|
|
5
7
|
#hasError = false;
|
|
6
8
|
#cssPath = "/css/nine-exception-hook.css";
|
|
9
|
+
#oldOnError = null;
|
|
7
10
|
|
|
8
11
|
constructor() {
|
|
9
12
|
super();
|
|
@@ -11,13 +14,13 @@ export class ExceptionHook extends HTMLElement {
|
|
|
11
14
|
this.attachShadow({ mode: 'open' });
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
// src/components/exception/ExceptionHook.js ๋ด๋ถ ์์
|
|
15
|
-
|
|
16
17
|
connectedCallback() {
|
|
17
18
|
this.#renderer();
|
|
18
19
|
this.#injectShadowStylesheet();
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
// ๐ฏ ๋ฆฌ์กํธ ๋ฐ ๊ฐ๋ฐ ์ค๋ฒ๋ ์ด์ stopPropagation์ ์ฐํํ๊ธฐ ์ํ ์ด์ค ์ค๋ํผ ๊ฐ๋
|
|
22
|
+
this.#setupGlobalSniffer();
|
|
23
|
+
|
|
21
24
|
window.addEventListener('unhandledrejection', this.#handlePromiseError, true);
|
|
22
25
|
window.addEventListener('popstate', this.#handleLocationChange);
|
|
23
26
|
document.addEventListener('click', this.#handleLocationChange, true);
|
|
@@ -28,18 +31,43 @@ export class ExceptionHook extends HTMLElement {
|
|
|
28
31
|
window.removeEventListener('unhandledrejection', this.#handlePromiseError, true);
|
|
29
32
|
window.removeEventListener('popstate', this.#handleLocationChange);
|
|
30
33
|
document.removeEventListener('click', this.#handleLocationChange, true);
|
|
34
|
+
|
|
35
|
+
// ๐ฏ ์์ onerror ํธ๋ค๋ฌ ๋ณต๊ตฌ
|
|
36
|
+
if (window.onerror === this.#handleRuntimeError || this.#oldOnError) {
|
|
37
|
+
window.onerror = this.#oldOnError;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
#setupGlobalSniffer() {
|
|
42
|
+
// ํ์ค ์บก์ฒ๋ง ๋ฆฌ์ค๋ ๋ฑ๋ก
|
|
43
|
+
window.addEventListener('error', this.#handleRuntimeError, true);
|
|
44
|
+
|
|
45
|
+
// ๐ฏ [์นํธํค] ํ ํ๋ ์์ํฌ๊ฐ ์ด๋ฒคํธ๋ฅผ ์ผ์ผ๋ ๋ฌด์กฐ๊ฑด ์คํ๋๋ ์์ hook ๊ฐ๋ก์ฑ๊ธฐ
|
|
46
|
+
this.#oldOnError = window.onerror;
|
|
47
|
+
window.onerror = (message, source, lineno, colno, error) => {
|
|
48
|
+
if (!this.#hasError) {
|
|
49
|
+
const errorMessage = error?.message || message || "์ ์ ์๋ ๋ฐํ์ ์์ธ";
|
|
50
|
+
const errorStack = error?.stack || `${source}:${lineno}:${colno}`;
|
|
51
|
+
this.#renderError(errorMessage, errorStack);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ๊ธฐ์กด์ ๋ฑ๋ก๋์ด ์๋ ๋ค๋ฅธ onerror ์์ง(Vite, ๋ธ๋ผ์ฐ์ ๋ฑ)์ด ์์ผ๋ฉด ๊ทธ๋๋ก ์คํ๋๋๋ก ์์
|
|
55
|
+
if (this.#oldOnError) {
|
|
56
|
+
return this.#oldOnError(message, source, lineno, colno, error);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
33
61
|
|
|
34
62
|
#renderer = () => {
|
|
35
63
|
const customImport = nine.cssPath ? `@import "${nine.cssPath}/nine-mu.css";` : "";
|
|
36
64
|
|
|
37
65
|
this.shadowRoot.innerHTML = `
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
<style>
|
|
67
|
+
@import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${__APP_VERSION__}/dist/css/nine-mu.css";
|
|
68
|
+
${customImport}
|
|
69
|
+
</style>
|
|
70
|
+
|
|
43
71
|
<div class="nine-hook-core">
|
|
44
72
|
<slot></slot>
|
|
45
73
|
</div>
|
|
@@ -48,7 +76,6 @@ export class ExceptionHook extends HTMLElement {
|
|
|
48
76
|
}
|
|
49
77
|
|
|
50
78
|
#injectShadowStylesheet() {
|
|
51
|
-
// ๐ก ๋ด๋ถ ํ๋ ํธ์ถ ์์๋ ๋ชจ๋ this.#ํ์์ผ๋ก ๋งคํํฉ๋๋ค.
|
|
52
79
|
if (this.shadowRoot.querySelector(`link[href="${this.#cssPath}"]`)) return;
|
|
53
80
|
|
|
54
81
|
const link = document.createElement('link');
|
|
@@ -60,27 +87,20 @@ export class ExceptionHook extends HTMLElement {
|
|
|
60
87
|
#handleRuntimeError = (event) => {
|
|
61
88
|
if (this.#hasError) return;
|
|
62
89
|
|
|
63
|
-
//
|
|
90
|
+
// ๐ฏ event.error๊ฐ null์ด๊ฑฐ๋ ์ ์ค๋๋๋ผ๋ message๋ฅผ ํตํด ์๋ฌ๋ฅผ ๋ฌด์กฐ๊ฑด ํฌ์ฐฉํฉ๋๋ค.
|
|
64
91
|
const errorMessage = event.error?.message || event.message || String(event);
|
|
65
92
|
const errorStack = event.error?.stack || "No stack trace available";
|
|
66
93
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
if (errorMessage) {
|
|
70
|
-
|
|
71
|
-
// 3. ๋ฆฌ์กํธ๊ฐ ์๋ฌ ๋๋ฌธ์ <slot> ๋ด๋ถ DOM์ ํต์งธ๋ก Unmount(ํ๊ดด)ํด๋ฒ๋ฆฌ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด
|
|
72
|
-
// ๋ธ๋ผ์ฐ์ ๋ฒ๋ธ๋ง์ ์ฆ์ ์ฐจ๋จํ๊ณ , ์๋ฌ ๋ณด๋๋ฅผ ์ฆ๊ฐ ๊ทธ๋ฆฌ๋๋ก ์์๋ฅผ ๊ฐ๋ก์ฑ๋๋ค.
|
|
94
|
+
// ๋ธ๋ผ์ฐ์ ๋ด๋ถ ์คํฌ๋ฆฝํธ ๋ก๋ฉ ์๋ฌ ์์ธ ์ฒ๋ฆฌ ํ ๊ฐ์ฐจ์์ด ๋ฐ์ธ๋ฉ
|
|
95
|
+
if (errorMessage && errorMessage !== "Script error.") {
|
|
73
96
|
this.#renderError(errorMessage, errorStack);
|
|
74
|
-
|
|
75
|
-
// ํ์์ ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๋นจ๊ฐ ์๋ฌ์ฐฝ(Vite Overlay ๋ฑ) ์ต์ ์ํ ๋ ํ์ฑํ
|
|
76
|
-
// event.preventDefault();
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
|
|
80
100
|
#handlePromiseError = (event) => {
|
|
81
101
|
if (this.#hasError) return;
|
|
82
102
|
|
|
83
|
-
// ๋น๋๊ธฐ
|
|
103
|
+
// ๋น๋๊ธฐ ๋น์ ์ ๋ฐํ์ ๊ฑฐ๋ถ(ex. null.data ์ฝ๊ธฐ ์๋ฌ) ์บ์น
|
|
84
104
|
const reason = event.reason;
|
|
85
105
|
const errorMessage = reason?.message || String(reason || "Unhandled Promise Rejection");
|
|
86
106
|
const errorStack = reason?.stack || "No stack trace available";
|
|
@@ -145,19 +165,19 @@ export class ExceptionHook extends HTMLElement {
|
|
|
145
165
|
if (!exceptionBoard) return;
|
|
146
166
|
|
|
147
167
|
const errorHTML = `
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
<div class="nine-error-container">
|
|
169
|
+
<h3 class="nine-error-title">โ ๏ธ ์์คํ
์์ธ ๊ฐ์ง (${this.tagName.toLowerCase()})</h3>
|
|
170
|
+
<p class="nine-error-label">[์๋ฌ ์์ธ ๋ก๊ทธ]:</p>
|
|
171
|
+
<pre class="nine-error-log">${errorMessage}</pre>
|
|
172
|
+
|
|
173
|
+
<div class="nine-action-area" style="margin-top: 20px; display: flex; align-items: center; gap: 15px;">
|
|
174
|
+
<button class="nine-ai-btn">๐ค AI์๊ฒ ์์ค์ฝ๋ ์์ ์์ฒญ</button>
|
|
175
|
+
<div class="nine-error-footer">
|
|
176
|
+
๋ฒํผ์ ๋๋ฅด๋ฉด AI๊ฐ ๋ก๊ทธ ๋ฐ ์ปดํฌ๋ํธ ๋งต์ ์ญ์ถ์ ํ์ฌ ์์ ์ ์์ํฉ๋๋ค.
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
`;
|
|
161
181
|
|
|
162
182
|
exceptionBoard.innerHTML = errorHTML;
|
|
163
183
|
|