@absolutejs/absolute 0.19.0-beta.147 → 0.19.0-beta.149

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.
@@ -198,17 +198,49 @@ export const handleVueUpdate = (message: {
198
198
  const clientStart = performance.now();
199
199
  const modulePath = `${pageModuleUrl}?t=${Date.now()}`;
200
200
 
201
- // When a composable/utility file changed (not the .vue file itself),
202
- // force a full page reload so setup() re-runs with the new composable.
203
- // Vue's rerender only swaps the template, not the setup closure.
204
- if (message.data.forceReload) {
205
- window.location.reload();
206
-
207
- return;
208
- }
209
-
210
201
  import(modulePath)
211
- .then(() => {
202
+ .then((mod) => {
203
+ // When a composable/utility file changed (not the .vue file itself),
204
+ // force reload via __VUE_HMR_RUNTIME__ so setup() re-runs.
205
+ // Vue's rerender only swaps the template, not the setup closure.
206
+ if (message.data.forceReload && (window as any).__VUE_HMR_RUNTIME__) {
207
+ const hmrRuntime = (window as any).__VUE_HMR_RUNTIME__;
208
+ const component = mod?.default ?? Object.values(mod ?? {})[0];
209
+ if (component?.__hmrId) {
210
+ hmrRuntime.reload(component.__hmrId, component);
211
+
212
+ // Restore preserved ref values into the new component instance.
213
+ // Only restores refs that exist in both old and new state with
214
+ // matching types. Skips functions and computed to avoid stale closures.
215
+ if (
216
+ window.__VUE_APP__?._instance &&
217
+ Object.keys(vuePreservedState).length > 0
218
+ ) {
219
+ try {
220
+ const inst = window.__VUE_APP__._instance;
221
+ const ss = inst.setupState;
222
+ if (ss) {
223
+ for (const key of Object.keys(vuePreservedState)) {
224
+ const newVal = ss[key];
225
+ const oldVal = vuePreservedState[key];
226
+ // Only restore into refs (objects with .value)
227
+ // and only if types match
228
+ if (
229
+ newVal &&
230
+ typeof newVal === 'object' &&
231
+ 'value' in newVal &&
232
+ typeof newVal.value === typeof oldVal
233
+ ) {
234
+ newVal.value = oldVal;
235
+ }
236
+ }
237
+ }
238
+ } catch {
239
+ // State shape mismatch — let it reset naturally
240
+ }
241
+ }
242
+ }
243
+ }
212
244
  sessionStorage.removeItem('__HMR_ACTIVE__');
213
245
 
214
246
  if (window.__HMR_WS__ && message.data.serverDuration != null) {
package/package.json CHANGED
@@ -164,5 +164,5 @@
164
164
  "typecheck": "bun run vue-tsc --noEmit"
165
165
  },
166
166
  "types": "./dist/src/index.d.ts",
167
- "version": "0.19.0-beta.147"
167
+ "version": "0.19.0-beta.149"
168
168
  }