@ms-cloudpack/overlay 0.19.58 → 0.19.60
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePackageUpdate.d.ts","sourceRoot":"","sources":["../src/handlePackageUpdate.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,mBAAmB,GAAU,MAAM,OAAO,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"handlePackageUpdate.d.ts","sourceRoot":"","sources":["../src/handlePackageUpdate.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,mBAAmB,GAAU,MAAM,OAAO,KAAG,OAAO,CAAC,IAAI,CAqFrE,CAAC"}
|
|
@@ -39,16 +39,18 @@ export const handlePackageUpdate = async (data) => {
|
|
|
39
39
|
// Check if this module was actually loaded using Performance API
|
|
40
40
|
// bundleUrl already has the new hash: http://localhost:5500/pkg@1.0.0/h-abc123-1234567890/v1.2/bundled/lib/file.js
|
|
41
41
|
// We normalize both URLs by removing the hash to compare them
|
|
42
|
-
|
|
42
|
+
// If bundleUrl is relative (starts with /), prepend the origin to make it absolute
|
|
43
|
+
const absoluteBundleUrl = bundleUrl.startsWith('/') ? `${window.location.origin}${bundleUrl}` : bundleUrl;
|
|
44
|
+
const normalizedBundleUrl = removeHashFromUrl(absoluteBundleUrl);
|
|
43
45
|
const wasLoaded = normalizedResources.some((r) => r === normalizedBundleUrl);
|
|
44
46
|
if (!wasLoaded) {
|
|
45
47
|
console.log(`[Cloudpack HMR] Skipping ${importPath} - not loaded on this page`);
|
|
46
48
|
continue;
|
|
47
49
|
}
|
|
48
|
-
console.log(`[Cloudpack HMR] Loading ${importPath} from ${
|
|
50
|
+
console.log(`[Cloudpack HMR] Loading ${importPath} from ${absoluteBundleUrl}`);
|
|
49
51
|
// Dynamic import - use webpackIgnore to bypass bundler's import analysis
|
|
50
52
|
// This ensures we use the browser's native import() for runtime URL
|
|
51
|
-
await import(/* webpackIgnore: true */
|
|
53
|
+
await import(/* webpackIgnore: true */ absoluteBundleUrl);
|
|
52
54
|
loadedCount++;
|
|
53
55
|
}
|
|
54
56
|
if (loadedCount === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePackageUpdate.js","sourceRoot":"","sources":["../src/handlePackageUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,IAAa,EAAiB,EAAE;IACxE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAA4B,CAAC;IAE3E,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,oCAAoC,WAAW,IAAI,OAAO,EAAE,CAAC,CAAC;QAE1E,wCAAwC;QACxC,MAAM,mBAAmB,GAAI,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAiC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9G,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAC1B,CAAC;QAEF,2BAA2B;QAC3B,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,KAAK,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC;YACpD,iEAAiE;YACjE,mHAAmH;YACnH,8DAA8D;YAC9D,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"handlePackageUpdate.js","sourceRoot":"","sources":["../src/handlePackageUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;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C,CAAC;QAC3E,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { PackageUpdatePayload } from '@ms-cloudpack/api-server/browser';\nimport { removeHashFromUrl } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Handles hot module replacement (HMR) updates for packages.\n *\n * This function is called when the development server notifies the client that a package\n * has been updated. It performs the following steps:\n *\n * 1. **Check which modules are loaded**: Uses Performance API to determine which entry points\n * from the package are actually loaded on the current page.\n *\n * 2. **Re-import updated modules**: Dynamically imports the new versions of loaded modules\n * using their updated bundle URLs (with new hash).\n *\n * 3. **Trigger React Refresh**: If React Refresh is available, triggers component updates\n * while preserving component state. Falls back to full page reload otherwise.\n *\n * The process ensures:\n * - Only relevant modules are updated (skip modules not loaded on current page)\n * - React component state is preserved when possible\n * - Graceful fallback to full reload if React Refresh fails\n *\n * @param data - The package update payload containing package name, version, and entry points\n *\n * @example\n * // This is typically called by the WebSocket message handler:\n * socket.on('package-update', (data) => {\n * await handlePackageUpdate(data);\n * });\n */\nexport const handlePackageUpdate = async (data: unknown): Promise<void> => {\n const { packageName, entryPoints, version } = data as PackageUpdatePayload;\n\n try {\n console.log(`[Cloudpack HMR] Package updated: ${packageName}@${version}`);\n\n // Get all loaded resources for checking\n const normalizedResources = (performance.getEntriesByType('resource') as PerformanceResourceTiming[]).map((r) =>\n removeHashFromUrl(r.name),\n );\n\n // Process each entry point\n let loadedCount = 0;\n for (const { importPath, bundleUrl } of entryPoints) {\n // Check if this module was actually loaded using Performance API\n // bundleUrl already has the new hash: http://localhost:5500/pkg@1.0.0/h-abc123-1234567890/v1.2/bundled/lib/file.js\n // We normalize both URLs by removing the hash to compare them\n // If bundleUrl is relative (starts with /), prepend the origin to make it absolute\n const absoluteBundleUrl = bundleUrl.startsWith('/') ? `${window.location.origin}${bundleUrl}` : bundleUrl;\n const normalizedBundleUrl = removeHashFromUrl(absoluteBundleUrl);\n const wasLoaded = normalizedResources.some((r) => r === normalizedBundleUrl);\n\n if (!wasLoaded) {\n console.log(`[Cloudpack HMR] Skipping ${importPath} - not loaded on this page`);\n continue;\n }\n\n console.log(`[Cloudpack HMR] Loading ${importPath} from ${absoluteBundleUrl}`);\n\n // Dynamic import - use webpackIgnore to bypass bundler's import analysis\n // This ensures we use the browser's native import() for runtime URL\n await import(/* webpackIgnore: true */ absoluteBundleUrl);\n loadedCount++;\n }\n\n if (loadedCount === 0) {\n console.log(`[Cloudpack HMR] No entry points from ${packageName} were loaded on this page`);\n return;\n }\n\n // ===== Trigger React Refresh =====\n //\n // React Refresh is a hot reloading feature that updates React components without losing state.\n // It allows developers to see component changes instantly while preserving:\n // - Component state (useState, useReducer)\n // - Form inputs\n // - Scroll position\n // - Any other runtime state\n //\n // How it works:\n // 1. When modules are re-imported above, React Refresh automatically detects changed components\n // 2. Components are registered via $RefreshReg$ calls (injected by the bundler during build)\n // 3. Calling performReactRefresh() re-renders the registered components with new code\n // 4. React's reconciliation preserves state by matching component types and positions\n //\n // The $RefreshRuntime$ global is initialized in registerReactRefresh.ts\n if (window.$RefreshRuntime$?.performReactRefresh) {\n // Perform the actual refresh - this will update all components that were re-registered\n // during the dynamic import above, while preserving their state\n const refreshResult = window.$RefreshRuntime$.performReactRefresh();\n\n if (refreshResult === null) {\n // Refresh returned null - this indicates no components were registered\n // This shouldn't happen if we successfully imported modules, so we fall back to full reload\n console.warn(`[Cloudpack HMR] React Refresh returned null despite registrations, reloading page`);\n window.location.reload();\n } else {\n // React components successfully updated with state preservation\n // refreshResult contains metadata about what was updated\n console.log(`[Cloudpack HMR] ✓ Updated ${packageName}@${version}`, refreshResult);\n }\n } else {\n // React Refresh runtime is not available\n // This happens when:\n // - React Refresh wasn't initialized (registerReactRefresh.ts not called)\n // - The app doesn't use React\n // - React Refresh was disabled\n // Fall back to full page reload to show the changes\n console.warn(`[Cloudpack HMR] React Refresh runtime not found, reloading page`);\n window.location.reload();\n }\n } catch (error) {\n console.error(`[Cloudpack HMR] ✗ Failed to update ${packageName}:`, error);\n window.location.reload();\n }\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/overlay",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.60",
|
|
4
4
|
"description": "The Cloudpack overlay UX",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prepack": "cp .npmignore dist/.npmignore"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ms-cloudpack/api-server": "^0.66.
|
|
32
|
+
"@ms-cloudpack/api-server": "^0.66.3",
|
|
33
33
|
"@ms-cloudpack/common-types": "^0.33.2",
|
|
34
34
|
"@ms-cloudpack/common-types-browser": "^0.6.5",
|
|
35
35
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|