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

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,25 @@ 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 with new data.
41
+ if (dataModuleUrl && refreshRuntime) {
42
+ const pageUrl = window.__REACT_PAGE_MODULE__;
43
+ if (pageUrl) {
44
+ applyDataThenPage(
45
+ dataModuleUrl,
46
+ pageUrl,
47
+ refreshRuntime,
48
+ serverDuration
49
+ );
50
+
51
+ return;
52
+ }
53
+ }
54
+
38
55
  if (pageModuleUrl && refreshRuntime) {
39
56
  applyRefreshImport(pageModuleUrl, refreshRuntime, serverDuration);
40
57
 
@@ -53,6 +70,21 @@ export const handleReactUpdate = (message: {
53
70
  window.location.reload();
54
71
  };
55
72
 
73
+ const sendTiming = (clientStart: number, serverDuration?: number) => {
74
+ if (window.__HMR_WS__) {
75
+ const clientMs = Math.round(performance.now() - clientStart);
76
+ const total = (serverDuration ?? 0) + clientMs;
77
+ window.__HMR_WS__.send(
78
+ JSON.stringify({ duration: total, type: 'hmr-timing' })
79
+ );
80
+ }
81
+ if (window.__ERROR_BOUNDARY__) {
82
+ window.__ERROR_BOUNDARY__.reset();
83
+ } else {
84
+ hideErrorOverlay();
85
+ }
86
+ };
87
+
56
88
  const applyRefreshImport = (
57
89
  moduleUrl: string,
58
90
  refreshRuntime: { performReactRefresh: () => unknown },
@@ -61,37 +93,34 @@ const applyRefreshImport = (
61
93
  const clientStart = performance.now();
62
94
  import(`${moduleUrl}?t=${Date.now()}`)
63
95
  .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
- }
96
+ refreshRuntime.performReactRefresh();
97
+ sendTiming(clientStart, serverDuration);
78
98
 
79
99
  return undefined;
80
100
  })
101
+ .catch((err) => {
102
+ console.warn(
103
+ '[HMR] React Fast Refresh failed, falling back to reload:',
104
+ err
105
+ );
106
+ window.location.reload();
107
+ });
108
+ };
109
+
110
+ const applyDataThenPage = (
111
+ dataUrl: string,
112
+ pageUrl: string,
113
+ refreshRuntime: { performReactRefresh: () => unknown },
114
+ serverDuration?: number
115
+ ) => {
116
+ const clientStart = performance.now();
117
+ // Import the changed data file first to bust the browser cache,
118
+ // then re-import the page so the component re-renders with new data.
119
+ import(`${dataUrl}?t=${Date.now()}`)
120
+ .then(() => import(`${pageUrl}?t=${Date.now()}`))
81
121
  .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
- }
122
+ refreshRuntime.performReactRefresh();
123
+ sendTiming(clientStart, serverDuration);
95
124
 
96
125
  return undefined;
97
126
  })
package/dist/index.js CHANGED
@@ -203450,38 +203450,15 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, parseError
203450
203450
  invalidateModule2(file4);
203451
203451
  }
203452
203452
  const isComponentFile = primaryFile.endsWith(".tsx") || primaryFile.endsWith(".jsx");
203453
- let broadcastFile = primaryFile;
203454
- if (!isComponentFile) {
203455
- const pageFile = reactFiles.find((f) => f.replace(/\\/g, "/").includes("/pages/") && (f.endsWith(".tsx") || f.endsWith(".jsx")));
203456
- if (pageFile) {
203457
- broadcastFile = pageFile;
203458
- } else {
203459
- const visited = new Set;
203460
- const queue = [resolve21(primaryFile)];
203461
- while (queue.length > 0) {
203462
- const current = queue.shift();
203463
- if (visited.has(current))
203464
- continue;
203465
- visited.add(current);
203466
- if (current.replace(/\\/g, "/").includes("/pages/") && (current.endsWith(".tsx") || current.endsWith(".jsx"))) {
203467
- broadcastFile = current;
203468
- break;
203469
- }
203470
- const deps = state.dependencyGraph.dependents.get(current);
203471
- if (deps) {
203472
- for (const dep of deps)
203473
- queue.push(dep);
203474
- }
203475
- }
203476
- }
203477
- }
203478
- const pageModuleUrl = await getReactModuleUrl(broadcastFile);
203453
+ const pageModuleUrl = await getReactModuleUrl(primaryFile);
203454
+ const dataModuleUrl = isComponentFile ? undefined : pageModuleUrl;
203479
203455
  if (pageModuleUrl) {
203480
203456
  const serverDuration = Date.now() - startTime;
203481
203457
  state.lastHmrPath = relative9(process.cwd(), primaryFile).replace(/\\/g, "/");
203482
203458
  state.lastHmrFramework = "react";
203483
203459
  broadcastToClients(state, {
203484
203460
  data: {
203461
+ dataModuleUrl,
203485
203462
  framework: "react",
203486
203463
  hasComponentChanges: true,
203487
203464
  hasCSSChanges: false,
@@ -205245,5 +205222,5 @@ export {
205245
205222
  ANGULAR_INIT_TIMEOUT_MS
205246
205223
  };
205247
205224
 
205248
- //# debugId=447483A2A4076C5F64756E2164756E21
205225
+ //# debugId=3F65A57A3B2221F364756E2164756E21
205249
205226
  //# sourceMappingURL=index.js.map