@lithent/hmr-parser 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@lithent/hmr-parser",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "description": "Lithent HMR parser utilities for build tools",
6
6
  "main": "./dist/lithentHmrParser.umd.js",
7
7
  "module": "./dist/lithentHmrParser.mjs",
package/src/strings.ts CHANGED
@@ -12,6 +12,7 @@ export const createHmrBootstrapBlock = (
12
12
  const __lithentModuleId = new URL(import.meta.url).pathname;
13
13
  const __lithentBoundaryStoreKey = \`__lithent_hmr_boundary__\${__lithentModuleId}\`;
14
14
  const __lithentDisposeStoreKey = \`__lithent_hmr_dispose__\${__lithentModuleId}\`;
15
+ const __lithentInvalidateCountKey = \`__lithent_hmr_invalidate_count__\${__lithentModuleId}\`;
15
16
  const __lithentGlobalStore =
16
17
  typeof globalThis === 'object'
17
18
  ? globalThis
@@ -85,6 +86,44 @@ const __lithentModuleHotStore =
85
86
 
86
87
  const __lithentHmrTargets = ${serializedTargets};
87
88
 
89
+ const __lithentGetInvalidateCount = () => {
90
+ return (__lithentGlobalStore && __lithentGlobalStore[__lithentInvalidateCountKey]) || 0;
91
+ };
92
+
93
+ const __lithentIncrementInvalidateCount = () => {
94
+ if (__lithentGlobalStore) {
95
+ const current = __lithentGetInvalidateCount();
96
+ __lithentGlobalStore[__lithentInvalidateCountKey] = current + 1;
97
+ return current + 1;
98
+ }
99
+ return 0;
100
+ };
101
+
102
+ const __lithentResetInvalidateCount = () => {
103
+ if (__lithentGlobalStore) {
104
+ __lithentGlobalStore[__lithentInvalidateCountKey] = 0;
105
+ }
106
+ };
107
+
108
+ const __lithentSafeInvalidate = (reason) => {
109
+ const MAX_INVALIDATE_ATTEMPTS = 3;
110
+ const count = __lithentIncrementInvalidateCount();
111
+
112
+ if (count >= MAX_INVALIDATE_ATTEMPTS) {
113
+ console.warn(
114
+ \`[Lithent HMR] 전체 리프레시를 \${count}번 시도했지만 계속 실패합니다. 컴포넌트가 마운트되지 않았거나 다른 문제가 있을 수 있습니다. 페이지를 수동으로 새로고침해주세요.\`,
115
+ reason
116
+ );
117
+ return;
118
+ }
119
+
120
+ console.warn(
121
+ \`[Lithent HMR] 변경된 경계를 적용하지 못해 전체 리프레시합니다. (시도 \${count}/\${MAX_INVALIDATE_ATTEMPTS})\`,
122
+ reason
123
+ );
124
+ import.meta.hot?.invalidate?.();
125
+ };
126
+
88
127
  const __lithentSetupHmrHooks = () => {
89
128
  if (!import.meta.hot) {
90
129
  return;
@@ -116,7 +155,9 @@ const __lithentSetupHmrHooks = () => {
116
155
  }
117
156
  }
118
157
 
119
- if (!applied) {
158
+ if (applied) {
159
+ __lithentResetInvalidateCount();
160
+ } else {
120
161
  if (missing.length && __lithentModuleHotStore) {
121
162
  queueMicrotask(() => {
122
163
  let retried = false;
@@ -126,19 +167,15 @@ const __lithentSetupHmrHooks = () => {
126
167
  retried = true;
127
168
  }
128
169
  }
129
- if (!retried) {
130
- console.warn(
131
- '[Lithent HMR] 변경된 경계를 적용하지 못해 전체 리프레시합니다.'
132
- );
133
- import.meta.hot?.invalidate?.();
170
+ if (retried) {
171
+ __lithentResetInvalidateCount();
172
+ } else {
173
+ __lithentSafeInvalidate(\`missing components: \${missing.join(', ')}\`);
134
174
  }
135
175
  });
136
176
  return;
137
177
  }
138
- console.warn(
139
- '[Lithent HMR] 변경된 경계를 적용하지 못해 전체 리프레시합니다.'
140
- );
141
- import.meta.hot?.invalidate?.();
178
+ __lithentSafeInvalidate('no components applied');
142
179
  }
143
180
  });
144
181
 
@@ -155,6 +192,9 @@ const __lithentSetupHmrHooks = () => {
155
192
  if (disposeApp) {
156
193
  __lithentGlobalStore[__lithentDisposeStoreKey] = disposeApp;
157
194
  }
195
+
196
+ // Reset invalidate count on dispose to allow fresh attempts on next load
197
+ __lithentResetInvalidateCount();
158
198
  }
159
199
  });
160
200
  };