@absolutejs/absolute 0.19.0-beta.63 → 0.19.0-beta.64

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.
@@ -8,6 +8,7 @@ import { detectCurrentFramework } from '../frameworkDetect';
8
8
 
9
9
  export const handleReactUpdate = (message: {
10
10
  data: {
11
+ dataModuleUrl?: string;
11
12
  hasCSSChanges?: boolean;
12
13
  hasComponentChanges?: boolean;
13
14
  manifest?: Record<string, string>;
@@ -32,9 +33,22 @@ export const handleReactUpdate = (message: {
32
33
 
33
34
  const refreshRuntime = window.$RefreshRuntime$;
34
35
  const serverDuration = message.data.serverDuration;
35
-
36
+ const dataModuleUrl = message.data.dataModuleUrl;
36
37
  const pageModuleUrl = message.data.pageModuleUrl;
37
38
 
39
+ // Non-component file: import the data file first (cache bust),
40
+ // then re-import the page so the component re-renders.
41
+ if (dataModuleUrl && pageModuleUrl && refreshRuntime) {
42
+ applyDataThenPage(
43
+ dataModuleUrl,
44
+ pageModuleUrl,
45
+ refreshRuntime,
46
+ serverDuration
47
+ );
48
+
49
+ return;
50
+ }
51
+
38
52
  if (pageModuleUrl && refreshRuntime) {
39
53
  applyRefreshImport(pageModuleUrl, refreshRuntime, serverDuration);
40
54
 
@@ -53,6 +67,21 @@ export const handleReactUpdate = (message: {
53
67
  window.location.reload();
54
68
  };
55
69
 
70
+ const sendTiming = (clientStart: number, serverDuration?: number) => {
71
+ if (window.__HMR_WS__) {
72
+ const clientMs = Math.round(performance.now() - clientStart);
73
+ const total = (serverDuration ?? 0) + clientMs;
74
+ window.__HMR_WS__.send(
75
+ JSON.stringify({ duration: total, type: 'hmr-timing' })
76
+ );
77
+ }
78
+ if (window.__ERROR_BOUNDARY__) {
79
+ window.__ERROR_BOUNDARY__.reset();
80
+ } else {
81
+ hideErrorOverlay();
82
+ }
83
+ };
84
+
56
85
  const applyRefreshImport = (
57
86
  moduleUrl: string,
58
87
  refreshRuntime: { performReactRefresh: () => unknown },
@@ -61,37 +90,34 @@ const applyRefreshImport = (
61
90
  const clientStart = performance.now();
62
91
  import(`${moduleUrl}?t=${Date.now()}`)
63
92
  .then(() => {
64
- const didRefresh = refreshRuntime.performReactRefresh();
65
-
66
- // If Fast Refresh was a no-op (data/utility file with no
67
- // component exports), re-import the page entry so the
68
- // component tree re-renders with the updated data.
69
- if (!didRefresh && window.__REACT_PAGE_MODULE__) {
70
- return import(
71
- `${window.__REACT_PAGE_MODULE__}?t=${Date.now()}`
72
- ).then(() => {
73
- refreshRuntime.performReactRefresh();
74
-
75
- return undefined;
76
- });
77
- }
93
+ refreshRuntime.performReactRefresh();
94
+ sendTiming(clientStart, serverDuration);
78
95
 
79
96
  return undefined;
80
97
  })
98
+ .catch((err) => {
99
+ console.warn(
100
+ '[HMR] React Fast Refresh failed, falling back to reload:',
101
+ err
102
+ );
103
+ window.location.reload();
104
+ });
105
+ };
106
+
107
+ const applyDataThenPage = (
108
+ dataUrl: string,
109
+ pageUrl: string,
110
+ refreshRuntime: { performReactRefresh: () => unknown },
111
+ serverDuration?: number
112
+ ) => {
113
+ const clientStart = performance.now();
114
+ // Import the changed data file first to bust the browser cache,
115
+ // then re-import the page so the component re-renders with new data.
116
+ import(`${dataUrl}?t=${Date.now()}`)
117
+ .then(() => import(`${pageUrl}?t=${Date.now()}`))
81
118
  .then(() => {
82
- if (window.__HMR_WS__) {
83
- const clientMs = Math.round(performance.now() - clientStart);
84
- const total = (serverDuration ?? 0) + clientMs;
85
- window.__HMR_WS__.send(
86
- JSON.stringify({ duration: total, type: 'hmr-timing' })
87
- );
88
- }
89
-
90
- if (window.__ERROR_BOUNDARY__) {
91
- window.__ERROR_BOUNDARY__.reset();
92
- } else {
93
- hideErrorOverlay();
94
- }
119
+ refreshRuntime.performReactRefresh();
120
+ sendTiming(clientStart, serverDuration);
95
121
 
96
122
  return undefined;
97
123
  })
package/dist/index.js CHANGED
@@ -203476,12 +203476,17 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, parseError
203476
203476
  }
203477
203477
  }
203478
203478
  const pageModuleUrl = await getReactModuleUrl(broadcastFile);
203479
+ let dataModuleUrl;
203480
+ if (!isComponentFile && broadcastFile !== primaryFile) {
203481
+ dataModuleUrl = await getReactModuleUrl(primaryFile);
203482
+ }
203479
203483
  if (pageModuleUrl) {
203480
203484
  const serverDuration = Date.now() - startTime;
203481
203485
  state.lastHmrPath = relative9(process.cwd(), primaryFile).replace(/\\/g, "/");
203482
203486
  state.lastHmrFramework = "react";
203483
203487
  broadcastToClients(state, {
203484
203488
  data: {
203489
+ dataModuleUrl,
203485
203490
  framework: "react",
203486
203491
  hasComponentChanges: true,
203487
203492
  hasCSSChanges: false,
@@ -205245,5 +205250,5 @@ export {
205245
205250
  ANGULAR_INIT_TIMEOUT_MS
205246
205251
  };
205247
205252
 
205248
- //# debugId=447483A2A4076C5F64756E2164756E21
205253
+ //# debugId=B320936B9473DFEE64756E2164756E21
205249
205254
  //# sourceMappingURL=index.js.map