@lolyjs/core 0.1.0-alpha.3 → 0.1.0-alpha.5

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,6 +1395,9 @@ 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
+ },
1398
1401
  infrastructureLogging: {
1399
1402
  level: "error"
1400
1403
  },
@@ -5499,29 +5502,55 @@ async function navigate(nextUrl, handlers, options) {
5499
5502
  }
5500
5503
  function createClickHandler(navigate2) {
5501
5504
  return function handleClick(ev) {
5502
- if (ev.defaultPrevented) return;
5503
- if (ev.button !== 0) return;
5504
- if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5505
- const target = ev.target;
5506
- if (!target) return;
5507
- const tagName = target.tagName.toLowerCase();
5508
- const isInteractiveElement = tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.closest("input, textarea, button, select, [contenteditable]");
5509
- if (isInteractiveElement) return;
5510
- const anchor = target.closest("a[href]");
5511
- if (!anchor) return;
5512
- const href = anchor.getAttribute("href");
5513
- if (!href) return;
5514
- if (href.startsWith("#")) return;
5515
- const url = new URL(href, window.location.href);
5516
- if (url.origin !== window.location.origin) return;
5517
- if (anchor.target && anchor.target !== "_self") return;
5518
- ev.preventDefault();
5519
- const nextUrl = url.pathname + url.search;
5520
- const currentUrl = window.location.pathname + window.location.search;
5521
- if (nextUrl === currentUrl) return;
5522
- const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5523
- window.history.pushState({}, "", nextUrl);
5524
- navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5505
+ 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;
5510
+ 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") {
5515
+ return;
5516
+ }
5517
+ }
5518
+ }
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") {
5523
+ return;
5524
+ }
5525
+ const interactiveParent = target.closest("input, textarea, button, select, [contenteditable], label");
5526
+ if (interactiveParent) {
5527
+ if (interactiveParent.tagName.toLowerCase() === "label") {
5528
+ const label = interactiveParent;
5529
+ if (label.control) {
5530
+ return;
5531
+ }
5532
+ } else {
5533
+ return;
5534
+ }
5535
+ }
5536
+ const anchor = target.closest("a[href]");
5537
+ if (!anchor) return;
5538
+ const href = anchor.getAttribute("href");
5539
+ if (!href) return;
5540
+ if (href.startsWith("#")) return;
5541
+ const url = new URL(href, window.location.href);
5542
+ if (url.origin !== window.location.origin) return;
5543
+ if (anchor.target && anchor.target !== "_self") return;
5544
+ ev.preventDefault();
5545
+ const nextUrl = url.pathname + url.search;
5546
+ const currentUrl = window.location.pathname + window.location.search;
5547
+ if (nextUrl === currentUrl) return;
5548
+ const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5549
+ window.history.pushState({}, "", nextUrl);
5550
+ navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5551
+ } catch (error) {
5552
+ console.error("[navigation] Error in click handler:", error);
5553
+ }
5525
5554
  };
5526
5555
  }
5527
5556
  function createPopStateHandler(navigate2) {
@@ -5540,25 +5569,36 @@ function AppShell({
5540
5569
  errorRoute
5541
5570
  }) {
5542
5571
  const [state, setState] = (0, import_react2.useState)(initialState);
5572
+ const handlersRef = (0, import_react2.useRef)({
5573
+ setState,
5574
+ routes,
5575
+ notFoundRoute,
5576
+ errorRoute
5577
+ });
5543
5578
  (0, import_react2.useEffect)(() => {
5544
- const handlers = {
5579
+ handlersRef.current = {
5545
5580
  setState,
5546
5581
  routes,
5547
5582
  notFoundRoute,
5548
5583
  errorRoute
5549
5584
  };
5585
+ }, [routes, notFoundRoute, errorRoute]);
5586
+ (0, import_react2.useEffect)(() => {
5587
+ let isMounted = true;
5550
5588
  async function handleNavigate(nextUrl, options) {
5551
- await navigate(nextUrl, handlers, options);
5589
+ if (!isMounted) return;
5590
+ await navigate(nextUrl, handlersRef.current, options);
5552
5591
  }
5553
5592
  const handleClick = createClickHandler(handleNavigate);
5554
5593
  const handlePopState = createPopStateHandler(handleNavigate);
5555
- window.addEventListener("click", handleClick);
5556
- window.addEventListener("popstate", handlePopState);
5594
+ window.addEventListener("click", handleClick, false);
5595
+ window.addEventListener("popstate", handlePopState, false);
5557
5596
  return () => {
5558
- window.removeEventListener("click", handleClick);
5559
- window.removeEventListener("popstate", handlePopState);
5597
+ isMounted = false;
5598
+ window.removeEventListener("click", handleClick, false);
5599
+ window.removeEventListener("popstate", handlePopState, false);
5560
5600
  };
5561
- }, [routes, notFoundRoute, errorRoute]);
5601
+ }, []);
5562
5602
  const isError = state.route === errorRoute;
5563
5603
  const isNotFound = state.route === notFoundRoute;
5564
5604
  const routeType = isError ? "error" : isNotFound ? "notfound" : "normal";