@lolyjs/core 0.1.0-alpha.5 → 0.1.0-alpha.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/index.cjs CHANGED
@@ -1395,9 +1395,6 @@ function createClientConfig(projectRoot, mode) {
1395
1395
  filename: mode === "production" ? "client.[contenthash].css" : "client.css"
1396
1396
  })
1397
1397
  ],
1398
- externals: {
1399
- "@lolyjs/core/runtime": "@lolyjs/core/runtime"
1400
- },
1401
1398
  infrastructureLogging: {
1402
1399
  level: "error"
1403
1400
  },
@@ -5144,6 +5141,11 @@ var import_react2 = require("react");
5144
5141
  // modules/runtime/client/RouterView.tsx
5145
5142
  var import_jsx_runtime = require("react/jsx-runtime");
5146
5143
  function RouterView({ state }) {
5144
+ console.log("[loly:RouterView] Rendering", {
5145
+ url: state.url,
5146
+ hasRoute: !!state.route,
5147
+ hasComponents: !!state.components
5148
+ });
5147
5149
  if (!state.route) {
5148
5150
  if (state.components === null) {
5149
5151
  return null;
@@ -5155,6 +5157,11 @@ function RouterView({ state }) {
5155
5157
  }
5156
5158
  const { Page, layouts } = state.components;
5157
5159
  const { params, props } = state;
5160
+ console.log("[loly:RouterView] Creating page element", {
5161
+ hasPage: !!Page,
5162
+ layoutsCount: layouts.length,
5163
+ paramsKeys: Object.keys(params)
5164
+ });
5158
5165
  let element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Page, { params, ...props });
5159
5166
  const layoutChain = layouts.slice().reverse();
5160
5167
  for (const Layout of layoutChain) {
@@ -5502,24 +5509,50 @@ async function navigate(nextUrl, handlers, options) {
5502
5509
  }
5503
5510
  function createClickHandler(navigate2) {
5504
5511
  return function handleClick(ev) {
5512
+ const target = ev.target;
5513
+ const tagName = target?.tagName.toLowerCase() || "unknown";
5514
+ console.log("[loly:click] Click event received", {
5515
+ type: ev.type,
5516
+ tagName,
5517
+ target: target?.tagName,
5518
+ defaultPrevented: ev.defaultPrevented,
5519
+ button: ev.button,
5520
+ clientX: ev.clientX,
5521
+ clientY: ev.clientY
5522
+ });
5505
5523
  try {
5506
- if (ev.defaultPrevented) return;
5507
- if (ev.type !== "click") return;
5508
- if (ev.button !== 0) return;
5509
- if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5524
+ if (ev.defaultPrevented) {
5525
+ console.log("[loly:click] Event already prevented, skipping");
5526
+ return;
5527
+ }
5528
+ if (ev.type !== "click") {
5529
+ console.log("[loly:click] Not a click event, skipping", { type: ev.type });
5530
+ return;
5531
+ }
5532
+ if (ev.button !== 0) {
5533
+ console.log("[loly:click] Not left button, skipping", { button: ev.button });
5534
+ return;
5535
+ }
5536
+ if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) {
5537
+ console.log("[loly:click] Modifier keys pressed, skipping");
5538
+ return;
5539
+ }
5510
5540
  if (ev.clientX === 0 && ev.clientY === 0 && ev.detail === 0) {
5511
- const target2 = ev.target;
5512
- if (target2) {
5513
- const tagName2 = target2.tagName.toLowerCase();
5514
- if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select") {
5541
+ if (target) {
5542
+ const tagName3 = target.tagName.toLowerCase();
5543
+ if (tagName3 === "input" || tagName3 === "textarea" || tagName3 === "button" || tagName3 === "select") {
5544
+ console.log("[loly:click] Synthetic event on interactive element, skipping", { tagName: tagName3 });
5515
5545
  return;
5516
5546
  }
5517
5547
  }
5518
5548
  }
5519
- const target = ev.target;
5520
- if (!target) return;
5521
- const tagName = target.tagName.toLowerCase();
5522
- if (tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
5549
+ if (!target) {
5550
+ console.log("[loly:click] No target, skipping");
5551
+ return;
5552
+ }
5553
+ const tagName2 = target.tagName.toLowerCase();
5554
+ if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
5555
+ console.log("[loly:click] Target is interactive element, skipping", { tagName: tagName2 });
5523
5556
  return;
5524
5557
  }
5525
5558
  const interactiveParent = target.closest("input, textarea, button, select, [contenteditable], label");
@@ -5527,29 +5560,60 @@ function createClickHandler(navigate2) {
5527
5560
  if (interactiveParent.tagName.toLowerCase() === "label") {
5528
5561
  const label = interactiveParent;
5529
5562
  if (label.control) {
5563
+ console.log("[loly:click] Inside label with control, skipping");
5530
5564
  return;
5531
5565
  }
5532
5566
  } else {
5567
+ console.log("[loly:click] Inside interactive parent, skipping", {
5568
+ parentTag: interactiveParent.tagName.toLowerCase()
5569
+ });
5533
5570
  return;
5534
5571
  }
5535
5572
  }
5536
5573
  const anchor = target.closest("a[href]");
5537
- if (!anchor) return;
5574
+ if (!anchor) {
5575
+ console.log("[loly:click] No anchor found, skipping");
5576
+ return;
5577
+ }
5578
+ console.log("[loly:click] Anchor found, processing navigation", {
5579
+ href: anchor.getAttribute("href")
5580
+ });
5538
5581
  const href = anchor.getAttribute("href");
5539
- if (!href) return;
5540
- if (href.startsWith("#")) return;
5582
+ if (!href) {
5583
+ console.log("[loly:click] No href attribute, skipping");
5584
+ return;
5585
+ }
5586
+ if (href.startsWith("#")) {
5587
+ console.log("[loly:click] Hash link, skipping");
5588
+ return;
5589
+ }
5541
5590
  const url = new URL(href, window.location.href);
5542
- if (url.origin !== window.location.origin) return;
5543
- if (anchor.target && anchor.target !== "_self") return;
5591
+ if (url.origin !== window.location.origin) {
5592
+ console.log("[loly:click] External link, skipping", { origin: url.origin });
5593
+ return;
5594
+ }
5595
+ if (anchor.target && anchor.target !== "_self") {
5596
+ console.log("[loly:click] Link has target, skipping", { target: anchor.target });
5597
+ return;
5598
+ }
5544
5599
  ev.preventDefault();
5600
+ console.log("[loly:click] Prevented default, navigating");
5545
5601
  const nextUrl = url.pathname + url.search;
5546
5602
  const currentUrl = window.location.pathname + window.location.search;
5547
- if (nextUrl === currentUrl) return;
5603
+ if (nextUrl === currentUrl) {
5604
+ console.log("[loly:click] Same URL, skipping", { nextUrl });
5605
+ return;
5606
+ }
5548
5607
  const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5608
+ console.log("[loly:click] Pushing state and navigating", {
5609
+ nextUrl,
5610
+ currentUrl,
5611
+ shouldRevalidate
5612
+ });
5549
5613
  window.history.pushState({}, "", nextUrl);
5550
5614
  navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5551
5615
  } catch (error) {
5552
- console.error("[navigation] Error in click handler:", error);
5616
+ console.error("[loly:click] Error in click handler:", error);
5553
5617
  }
5554
5618
  };
5555
5619
  }
@@ -5568,6 +5632,10 @@ function AppShell({
5568
5632
  notFoundRoute,
5569
5633
  errorRoute
5570
5634
  }) {
5635
+ console.log("[loly:AppShell] Component rendering", {
5636
+ url: initialState.url,
5637
+ hasRoute: !!initialState.route
5638
+ });
5571
5639
  const [state, setState] = (0, import_react2.useState)(initialState);
5572
5640
  const handlersRef = (0, import_react2.useRef)({
5573
5641
  setState,
@@ -5576,6 +5644,11 @@ function AppShell({
5576
5644
  errorRoute
5577
5645
  });
5578
5646
  (0, import_react2.useEffect)(() => {
5647
+ console.log("[loly:AppShell] Updating handlersRef", {
5648
+ routesCount: routes.length,
5649
+ hasNotFound: !!notFoundRoute,
5650
+ hasError: !!errorRoute
5651
+ });
5579
5652
  handlersRef.current = {
5580
5653
  setState,
5581
5654
  routes,
@@ -5584,16 +5657,34 @@ function AppShell({
5584
5657
  };
5585
5658
  }, [routes, notFoundRoute, errorRoute]);
5586
5659
  (0, import_react2.useEffect)(() => {
5660
+ const effectId = Math.random().toString(36).substring(7);
5661
+ console.log("[loly:AppShell] Setting up event listeners", { effectId });
5587
5662
  let isMounted = true;
5663
+ let listenerCount = 0;
5588
5664
  async function handleNavigate(nextUrl, options) {
5589
- if (!isMounted) return;
5665
+ if (!isMounted) {
5666
+ console.warn("[loly:AppShell] navigate called but component is unmounted");
5667
+ return;
5668
+ }
5669
+ console.log("[loly:AppShell] Navigating to", nextUrl, options);
5590
5670
  await navigate(nextUrl, handlersRef.current, options);
5591
5671
  }
5592
5672
  const handleClick = createClickHandler(handleNavigate);
5593
5673
  const handlePopState = createPopStateHandler(handleNavigate);
5594
5674
  window.addEventListener("click", handleClick, false);
5595
5675
  window.addEventListener("popstate", handlePopState, false);
5676
+ listenerCount = 2;
5677
+ console.log("[loly:AppShell] Event listeners added", {
5678
+ clickListener: true,
5679
+ popStateListener: true,
5680
+ totalListeners: listenerCount
5681
+ });
5596
5682
  return () => {
5683
+ console.log("[loly:AppShell] Cleaning up event listeners", {
5684
+ effectId,
5685
+ wasMounted: isMounted,
5686
+ listenersToRemove: listenerCount
5687
+ });
5597
5688
  isMounted = false;
5598
5689
  window.removeEventListener("click", handleClick, false);
5599
5690
  window.removeEventListener("popstate", handlePopState, false);
@@ -5648,14 +5739,25 @@ async function loadInitialRoute(initialUrl, initialData, routes, notFoundRoute,
5648
5739
  };
5649
5740
  }
5650
5741
  function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
5742
+ console.log("[loly:runtime] bootstrapClient called", {
5743
+ routesCount: routes.length,
5744
+ hasNotFound: !!notFoundRoute,
5745
+ hasError: !!errorRoute
5746
+ });
5651
5747
  (async function bootstrap() {
5652
5748
  const container = document.getElementById(APP_CONTAINER_ID2);
5653
5749
  const initialData = getWindowData();
5750
+ console.log("[loly:runtime] bootstrap starting", {
5751
+ hasContainer: !!container,
5752
+ containerId: APP_CONTAINER_ID2,
5753
+ hasInitialData: !!initialData
5754
+ });
5654
5755
  if (!container) {
5655
- console.error(`Container #${APP_CONTAINER_ID2} not found for hydration`);
5756
+ console.error(`[loly:runtime] Container #${APP_CONTAINER_ID2} not found for hydration`);
5656
5757
  return;
5657
5758
  }
5658
5759
  const initialUrl = window.location.pathname + window.location.search;
5760
+ console.log("[loly:runtime] Loading initial route", { initialUrl });
5659
5761
  try {
5660
5762
  const initialState = await loadInitialRoute(
5661
5763
  initialUrl,
@@ -5664,9 +5766,15 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
5664
5766
  notFoundRoute,
5665
5767
  errorRoute
5666
5768
  );
5769
+ console.log("[loly:runtime] Initial route loaded", {
5770
+ url: initialState.url,
5771
+ hasRoute: !!initialState.route,
5772
+ hasComponents: !!initialState.components
5773
+ });
5667
5774
  if (initialData?.metadata) {
5668
5775
  applyMetadata(initialData.metadata);
5669
5776
  }
5777
+ console.log("[loly:runtime] Hydrating React app");
5670
5778
  (0, import_client5.hydrateRoot)(
5671
5779
  container,
5672
5780
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -5679,9 +5787,10 @@ function bootstrapClient(routes, notFoundRoute, errorRoute = null) {
5679
5787
  }
5680
5788
  )
5681
5789
  );
5790
+ console.log("[loly:runtime] React app hydrated successfully");
5682
5791
  } catch (error) {
5683
5792
  console.error(
5684
- "[client] Error loading initial route components for",
5793
+ "[loly:runtime] Error loading initial route components for",
5685
5794
  initialUrl,
5686
5795
  error
5687
5796
  );