@vyckr/tachyon 1.3.6 → 1.3.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyckr/tachyon",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "A polyglot, file-system-routed full-stack framework for Bun",
5
5
  "author": "Chidelma",
6
6
  "license": "MIT",
@@ -372,17 +372,34 @@ function navigate(pathname: string) {
372
372
  };
373
373
 
374
374
  if (layoutPath && layoutChanged) {
375
- import(layoutPath).then(async (mod) => {
375
+ Promise.all([
376
+ import(layoutPath),
377
+ import(pageURL),
378
+ ]).then(async ([layoutMod, pageMod]) => {
376
379
  currentLayoutPath = layoutPath;
377
- layoutRender = await mod.default();
380
+ layoutRender = await layoutMod.default();
381
+
382
+ if (location.pathname !== pathname) history.pushState({}, '', pathname);
383
+ else history.replaceState({}, '', pathname);
384
+ pageRender = await pageMod.default();
385
+
378
386
  freshNavigation = true;
379
387
  previousHTML = '';
380
- try {
381
- document.body.innerHTML = await layoutRender!();
382
- } finally {
383
- freshNavigation = false;
384
- }
385
- await loadPage();
388
+ lazyLoaded.clear();
389
+ lazyRenders.clear();
390
+
391
+ // Render layout and page content in one DOM write to eliminate CLS
392
+ const layoutHTML = await layoutRender!();
393
+ const pageHTML = await pageRender();
394
+ previousHTML = pageHTML;
395
+
396
+ const tempDoc = parser.parseFromString(`<body>${layoutHTML}</body>`, 'text/html');
397
+ const slot = tempDoc.getElementById('ty-layout-slot');
398
+ if (slot) slot.innerHTML = pageHTML;
399
+ document.body.innerHTML = tempDoc.body.innerHTML;
400
+
401
+ postPatch();
402
+ freshNavigation = false;
386
403
  });
387
404
  } else if (!layoutPath && currentLayoutPath) {
388
405
  // Leaving a layout