almostnode 0.2.2 → 0.2.3

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/index.mjs CHANGED
@@ -12554,6 +12554,9 @@ export default function Head({ children }) {
12554
12554
  if (pathname.startsWith("/_next/shims/")) {
12555
12555
  return this.serveNextShim(pathname);
12556
12556
  }
12557
+ if (pathname.startsWith("/_next/pages/")) {
12558
+ return this.servePageComponent(pathname);
12559
+ }
12557
12560
  if (pathname.startsWith("/_next/static/")) {
12558
12561
  return this.serveStaticAsset(pathname);
12559
12562
  }
@@ -12610,6 +12613,14 @@ export default function Head({ children }) {
12610
12613
  }
12611
12614
  return this.notFound(pathname);
12612
12615
  }
12616
+ async servePageComponent(pathname) {
12617
+ const route = pathname.replace("/_next/pages", "").replace(/\.js$/, "");
12618
+ const pageFile = this.resolvePageFile(route);
12619
+ if (!pageFile) {
12620
+ return this.notFound(pathname);
12621
+ }
12622
+ return this.transformAndServe(pageFile, pageFile);
12623
+ }
12613
12624
  async handleApiRoute(method, pathname, headers, body) {
12614
12625
  const apiFile = this.resolveApiFile(pathname);
12615
12626
  if (!apiFile) {
@@ -13323,7 +13334,6 @@ export default function Head({ children }) {
13323
13334
  }
13324
13335
  async generatePageHtml(pageFile, pathname) {
13325
13336
  const virtualPrefix = `/__virtual__/${this.port}`;
13326
- const pageModulePath = virtualPrefix + pageFile;
13327
13337
  const globalCssLinks = [];
13328
13338
  const cssLocations = [
13329
13339
  "/styles/globals.css",
@@ -13369,30 +13379,63 @@ export default function Head({ children }) {
13369
13379
  <script type="module">
13370
13380
  import React from 'react';
13371
13381
  import ReactDOM from 'react-dom/client';
13372
- import Page from '${pageModulePath}';
13373
13382
 
13374
- // Handle client-side navigation
13375
- function App() {
13376
- const [currentPath, setCurrentPath] = React.useState(window.location.pathname);
13383
+ const virtualBase = '${virtualPrefix}';
13377
13384
 
13378
- React.useEffect(() => {
13379
- const handlePopState = () => {
13380
- setCurrentPath(window.location.pathname);
13381
- // Defer reload outside React's update cycle
13382
- setTimeout(() => window.location.reload(), 0);
13383
- };
13385
+ // Convert URL path to page module path
13386
+ function getPageModulePath(pathname) {
13387
+ let route = pathname;
13388
+ if (route.startsWith(virtualBase)) {
13389
+ route = route.slice(virtualBase.length);
13390
+ }
13391
+ route = route.replace(/^\\/+/, '/') || '/';
13392
+ const modulePath = route === '/' ? '/index' : route;
13393
+ return virtualBase + '/_next/pages' + modulePath + '.js';
13394
+ }
13395
+
13396
+ // Dynamic page loader
13397
+ async function loadPage(pathname) {
13398
+ const modulePath = getPageModulePath(pathname);
13399
+ try {
13400
+ const module = await import(/* @vite-ignore */ modulePath);
13401
+ return module.default;
13402
+ } catch (e) {
13403
+ console.error('[Navigation] Failed to load:', modulePath, e);
13404
+ return null;
13405
+ }
13406
+ }
13407
+
13408
+ // Router component
13409
+ function Router() {
13410
+ const [Page, setPage] = React.useState(null);
13411
+ const [path, setPath] = React.useState(window.location.pathname);
13384
13412
 
13385
- window.addEventListener('popstate', handlePopState);
13386
- return () => window.removeEventListener('popstate', handlePopState);
13413
+ React.useEffect(() => {
13414
+ loadPage(path).then(C => C && setPage(() => C));
13387
13415
  }, []);
13388
13416
 
13417
+ React.useEffect(() => {
13418
+ const handleNavigation = async () => {
13419
+ const newPath = window.location.pathname;
13420
+ if (newPath !== path) {
13421
+ setPath(newPath);
13422
+ const C = await loadPage(newPath);
13423
+ if (C) setPage(() => C);
13424
+ }
13425
+ };
13426
+ window.addEventListener('popstate', handleNavigation);
13427
+ return () => window.removeEventListener('popstate', handleNavigation);
13428
+ }, [path]);
13429
+
13430
+ if (!Page) return null;
13389
13431
  return React.createElement(Page);
13390
13432
  }
13391
13433
 
13434
+ // Mark that we've initialized (for testing no-reload)
13435
+ window.__NEXT_INITIALIZED__ = Date.now();
13436
+
13392
13437
  ReactDOM.createRoot(document.getElementById('__next')).render(
13393
- React.createElement(React.StrictMode, null,
13394
- React.createElement(App)
13395
- )
13438
+ React.createElement(React.StrictMode, null, React.createElement(Router))
13396
13439
  );
13397
13440
  <\/script>
13398
13441
  </body>