@absolutejs/absolute 0.19.0-beta.38 → 0.19.0-beta.39

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
+ code?: string;
11
12
  hasCSSChanges?: boolean;
12
13
  hasComponentChanges?: boolean;
13
14
  manifest?: Record<string, string>;
@@ -32,10 +33,17 @@ export const handleReactUpdate = (message: {
32
33
  }
33
34
 
34
35
  const refreshRuntime = window.$RefreshRuntime$;
35
-
36
36
  const serverDuration = message.data.serverDuration;
37
37
 
38
- // ESM fast path: import the page module directly (no index re-import)
38
+ // Inline code path: transpiled code sent via WebSocket.
39
+ // Import from blob URL — no HTTP fetch, immune to bun --hot restarts.
40
+ if (message.data.code && refreshRuntime) {
41
+ applyInlineCode(message.data.code, refreshRuntime, serverDuration);
42
+
43
+ return;
44
+ }
45
+
46
+ // ESM fast path: import the page module directly
39
47
  const pageModuleUrl = message.data.pageModuleUrl;
40
48
 
41
49
  if (pageModuleUrl && refreshRuntime) {
@@ -58,6 +66,67 @@ export const handleReactUpdate = (message: {
58
66
  window.location.reload();
59
67
  };
60
68
 
69
+ // Import transpiled code from a blob URL — no HTTP fetch needed.
70
+ // Blob URLs resolve absolute imports (like /react/vendor/react.js)
71
+ // against the page's origin, so vendor imports work correctly.
72
+ const applyInlineCode = (
73
+ code: string,
74
+ refreshRuntime: { performReactRefresh: () => void },
75
+ serverDuration?: number
76
+ ) => {
77
+ const clientStart = performance.now();
78
+
79
+ // Convert absolute paths to full URLs so blob can resolve them
80
+ const origin = window.location.origin;
81
+ const fullCode = code.replace(
82
+ /(from\s*["'])(\/[^"']+)(["'])/g,
83
+ `$1${origin}$2$3`
84
+ );
85
+
86
+ const blob = new Blob([fullCode], { type: 'text/javascript' });
87
+ const blobUrl = URL.createObjectURL(blob);
88
+
89
+ import(blobUrl)
90
+ .then(() => {
91
+ URL.revokeObjectURL(blobUrl);
92
+ refreshRuntime.performReactRefresh();
93
+
94
+ if (window.__HMR_WS__) {
95
+ const fetchMs = Math.round(performance.now() - clientStart);
96
+ const total = (serverDuration ?? 0) + fetchMs;
97
+ window.__HMR_WS__.send(
98
+ JSON.stringify({
99
+ duration: total,
100
+ fetchMs,
101
+ refreshMs: 0,
102
+ serverMs: serverDuration ?? 0,
103
+ type: 'hmr-timing'
104
+ })
105
+ );
106
+ }
107
+
108
+ if (window.__ERROR_BOUNDARY__) {
109
+ window.__ERROR_BOUNDARY__.reset();
110
+ } else {
111
+ hideErrorOverlay();
112
+ }
113
+
114
+ return undefined;
115
+ })
116
+ .catch((err) => {
117
+ URL.revokeObjectURL(blobUrl);
118
+ console.warn(
119
+ '[HMR] Inline code failed, falling back to fetch:',
120
+ err
121
+ );
122
+ applyRefreshImport(
123
+ '',
124
+ refreshRuntime,
125
+ serverDuration
126
+ );
127
+ });
128
+ };
129
+
61
130
  const applyRefreshImport = (
62
131
  moduleUrl: string,
63
132
  refreshRuntime: { performReactRefresh: () => void },
package/dist/index.js CHANGED
@@ -202180,6 +202180,13 @@ var init_pageHandler = __esm(() => {
202180
202180
  });
202181
202181
 
202182
202182
  // src/dev/transformCache.ts
202183
+ var exports_transformCache = {};
202184
+ __export(exports_transformCache, {
202185
+ setTransformed: () => setTransformed,
202186
+ invalidateAll: () => invalidateAll,
202187
+ invalidate: () => invalidate,
202188
+ getTransformed: () => getTransformed
202189
+ });
202183
202190
  import { statSync } from "fs";
202184
202191
  var globalStore, cache, getTransformed = (filePath) => {
202185
202192
  const entry = cache.get(filePath);
@@ -202197,6 +202204,8 @@ var globalStore, cache, getTransformed = (filePath) => {
202197
202204
  cache.set(filePath, { content, mtime });
202198
202205
  }, invalidate = (filePath) => {
202199
202206
  cache.delete(filePath);
202207
+ }, invalidateAll = () => {
202208
+ cache.clear();
202200
202209
  };
202201
202210
  var init_transformCache = __esm(() => {
202202
202211
  globalStore = globalThis;
@@ -202982,13 +202991,15 @@ var parseErrorLocationFromMessage = (msg) => {
202982
202991
  const clientManifest = generateManifest2(clientResult.outputs, buildDir);
202983
202992
  Object.assign(state.manifest, clientManifest);
202984
202993
  await populateAssetStore(state.assetStore, clientManifest, buildDir);
202985
- }, getReactModuleUrl = async (pageFile) => {
202994
+ }, getReactModule = async (pageFile) => {
202986
202995
  const { invalidateModule: invalidateModule2, warmCache: warmCache2, SRC_URL_PREFIX: SRC_URL_PREFIX2 } = await Promise.resolve().then(() => (init_moduleServer(), exports_moduleServer));
202996
+ const { getTransformed: getTransformed2 } = await Promise.resolve().then(() => (init_transformCache(), exports_transformCache));
202987
202997
  invalidateModule2(pageFile);
202988
202998
  const rel = relative8(process.cwd(), pageFile).replace(/\\/g, "/");
202989
202999
  const url = `${SRC_URL_PREFIX2}${rel}`;
202990
203000
  warmCache2(url);
202991
- return url;
203001
+ const code = getTransformed2(resolve21(pageFile));
203002
+ return { code, url };
202992
203003
  }, handleReactFastPath = async (state, config, filesToRebuild, startTime, onRebuildComplete) => {
202993
203004
  const reactDir = config.reactDirectory ?? "";
202994
203005
  const reactPagesPath = resolve21(reactDir, "pages");
@@ -202998,18 +203009,19 @@ var parseErrorLocationFromMessage = (msg) => {
202998
203009
  if (reactFiles.length > 0) {
202999
203010
  const [changedFile] = reactFiles;
203000
203011
  if (changedFile) {
203001
- const pageModuleUrl = await getReactModuleUrl(changedFile);
203002
- if (pageModuleUrl) {
203012
+ const { code, url } = await getReactModule(changedFile);
203013
+ if (url) {
203003
203014
  const serverDuration = Date.now() - startTime;
203004
203015
  state.lastHmrPath = changedFile;
203005
203016
  state.lastHmrFramework = "react";
203006
203017
  broadcastToClients(state, {
203007
203018
  data: {
203019
+ code,
203008
203020
  framework: "react",
203009
203021
  hasComponentChanges: true,
203010
203022
  hasCSSChanges: false,
203011
203023
  manifest: state.manifest,
203012
- pageModuleUrl,
203024
+ pageModuleUrl: url,
203013
203025
  primarySource: changedFile,
203014
203026
  serverDuration,
203015
203027
  sourceFiles: reactFiles
@@ -204652,5 +204664,5 @@ export {
204652
204664
  ANGULAR_INIT_TIMEOUT_MS
204653
204665
  };
204654
204666
 
204655
- //# debugId=C7E8263A117DC2CD64756E2164756E21
204667
+ //# debugId=2F1F7365135EB02E64756E2164756E21
204656
204668
  //# sourceMappingURL=index.js.map