@elurjs/kit 2.4.7 → 2.4.8

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.
package/dist/lib/cli.js CHANGED
@@ -211,19 +211,23 @@ function buildEntrySource(islands, outFile, hydrateImport = "@elurjs/kit/island"
211
211
  const islandHydration = registryLines ? `const registry = {
212
212
  ${registryLines}
213
213
  };
214
- // Defer hydration until the browser is idle so the first paint is not
215
- // blocked. Islands with directive "load" already have SSR-rendered DOM,
216
- // so the user sees content immediately hydration only adds interactivity.
217
- const hydrate = () => hydrateIslands(registry);
214
+ // Dynamically import the hydrator so Vite splits it into a separate chunk.
215
+ // This keeps the initial entry-client bundle small (router only) — the
216
+ // hydrator loads on idle, after the first paint.
217
+ const hydrate = async () => {
218
+ const { hydrateIslands, cleanupHydratedIslands } = await import(${JSON.stringify(hydrateImport)});
219
+ cleanupHydratedIslands();
220
+ hydrateIslands(registry);
221
+ document.addEventListener("elur:rendered", () => {
222
+ cleanupHydratedIslands();
223
+ hydrateIslands(registry);
224
+ });
225
+ };
218
226
  if ("requestIdleCallback" in window) {
219
227
  requestIdleCallback(hydrate, { timeout: 2000 });
220
228
  } else {
221
229
  setTimeout(hydrate, 0);
222
230
  }
223
- document.addEventListener("elur:rendered", () => {
224
- cleanupHydratedIslands();
225
- hydrateIslands(registry);
226
- });
227
231
 
228
232
  // Vite HMR: when an island module (or the entry itself) updates, dispose the
229
233
  // current islands and re-hydrate from the updated modules — the registry's
@@ -231,8 +235,7 @@ document.addEventListener("elur:rendered", () => {
231
235
  // needed (progressive enhancement, audit §10.2 / §12.2).
232
236
  if (import.meta.hot) {
233
237
  import.meta.hot.accept((newModule) => {
234
- cleanupHydratedIslands();
235
- hydrateIslands(registry);
238
+ hydrate();
236
239
  if (newModule) {
237
240
  // Re-run the module so its side effects (router, listeners) apply.
238
241
  }
@@ -240,7 +243,6 @@ if (import.meta.hot) {
240
243
  }` : "";
241
244
  return `// AUTO-GENERATED by @elurjs/kit. Do not edit.
242
245
  import { startClientRouter } from ${JSON.stringify(routerImport)};
243
- import { hydrateIslands, cleanupHydratedIslands } from ${JSON.stringify(hydrateImport)};
244
246
 
245
247
  startClientRouter();
246
248
  ${islandHydration}