@elurjs/kit 2.4.6 → 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,11 +211,23 @@ function buildEntrySource(islands, outFile, hydrateImport = "@elurjs/kit/island"
211
211
  const islandHydration = registryLines ? `const registry = {
212
212
  ${registryLines}
213
213
  };
214
- hydrateIslands(registry);
215
- document.addEventListener("elur:rendered", () => {
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)});
216
219
  cleanupHydratedIslands();
217
220
  hydrateIslands(registry);
218
- });
221
+ document.addEventListener("elur:rendered", () => {
222
+ cleanupHydratedIslands();
223
+ hydrateIslands(registry);
224
+ });
225
+ };
226
+ if ("requestIdleCallback" in window) {
227
+ requestIdleCallback(hydrate, { timeout: 2000 });
228
+ } else {
229
+ setTimeout(hydrate, 0);
230
+ }
219
231
 
220
232
  // Vite HMR: when an island module (or the entry itself) updates, dispose the
221
233
  // current islands and re-hydrate from the updated modules — the registry's
@@ -223,8 +235,7 @@ document.addEventListener("elur:rendered", () => {
223
235
  // needed (progressive enhancement, audit §10.2 / §12.2).
224
236
  if (import.meta.hot) {
225
237
  import.meta.hot.accept((newModule) => {
226
- cleanupHydratedIslands();
227
- hydrateIslands(registry);
238
+ hydrate();
228
239
  if (newModule) {
229
240
  // Re-run the module so its side effects (router, listeners) apply.
230
241
  }
@@ -232,7 +243,6 @@ if (import.meta.hot) {
232
243
  }` : "";
233
244
  return `// AUTO-GENERATED by @elurjs/kit. Do not edit.
234
245
  import { startClientRouter } from ${JSON.stringify(routerImport)};
235
- import { hydrateIslands, cleanupHydratedIslands } from ${JSON.stringify(hydrateImport)};
236
246
 
237
247
  startClientRouter();
238
248
  ${islandHydration}