@lolyjs/core 0.1.0-alpha.1 → 0.1.0-alpha.10

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.js CHANGED
@@ -3466,7 +3466,7 @@ function createLogger(options = {}) {
3466
3466
  const baseConfig = {
3467
3467
  level,
3468
3468
  base: {
3469
- name: "@loly/core",
3469
+ name: "@lolyjs/core",
3470
3470
  env: process.env.NODE_ENV || "development"
3471
3471
  },
3472
3472
  timestamp: pino.stdTimeFunctions.isoTime,
@@ -4826,7 +4826,7 @@ async function renderStaticRoute(projectRoot, ssgOutDir, route, urlPath, params)
4826
4826
  initialData,
4827
4827
  meta: loaderResult.metadata,
4828
4828
  titleFallback: "My Framework Dev",
4829
- descriptionFallback: "Static page generated by @loly/core.",
4829
+ descriptionFallback: "Static page generated by @lolyjs/core.",
4830
4830
  chunkHref,
4831
4831
  clientJsPath,
4832
4832
  clientCssPath
@@ -5094,7 +5094,7 @@ function applyMetadata(md) {
5094
5094
  }
5095
5095
 
5096
5096
  // modules/runtime/client/AppShell.tsx
5097
- import { useEffect, useState } from "react";
5097
+ import { useEffect, useState, useRef } from "react";
5098
5098
 
5099
5099
  // modules/runtime/client/RouterView.tsx
5100
5100
  import { jsx } from "react/jsx-runtime";
@@ -5415,7 +5415,6 @@ async function navigate(nextUrl, handlers, options) {
5415
5415
  revalidate: options?.revalidate
5416
5416
  });
5417
5417
  if (json && json.error) {
5418
- console.log("[client] Error detected in response:", json);
5419
5418
  if (errorRoute) {
5420
5419
  const handled = await handleErrorRoute(
5421
5420
  nextUrl,
@@ -5457,26 +5456,54 @@ async function navigate(nextUrl, handlers, options) {
5457
5456
  }
5458
5457
  function createClickHandler(navigate2) {
5459
5458
  return function handleClick(ev) {
5460
- if (ev.defaultPrevented) return;
5461
- if (ev.button !== 0) return;
5462
- if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5463
- const target = ev.target;
5464
- if (!target) return;
5465
- const anchor = target.closest("a[href]");
5466
- if (!anchor) return;
5467
- const href = anchor.getAttribute("href");
5468
- if (!href) return;
5469
- if (href.startsWith("#")) return;
5470
- const url = new URL(href, window.location.href);
5471
- if (url.origin !== window.location.origin) return;
5472
- if (anchor.target && anchor.target !== "_self") return;
5473
- ev.preventDefault();
5474
- const nextUrl = url.pathname + url.search;
5475
- const currentUrl = window.location.pathname + window.location.search;
5476
- if (nextUrl === currentUrl) return;
5477
- const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5478
- window.history.pushState({}, "", nextUrl);
5479
- navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5459
+ try {
5460
+ if (ev.defaultPrevented) return;
5461
+ if (ev.type !== "click") return;
5462
+ if (ev.button !== 0) return;
5463
+ if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
5464
+ const target = ev.target;
5465
+ if (ev.clientX === 0 && ev.clientY === 0 && ev.detail === 0) {
5466
+ if (target) {
5467
+ const tagName2 = target.tagName.toLowerCase();
5468
+ if (tagName2 === "input" || tagName2 === "textarea" || tagName2 === "button" || tagName2 === "select") {
5469
+ return;
5470
+ }
5471
+ }
5472
+ }
5473
+ if (!target) return;
5474
+ const tagName = target.tagName.toLowerCase();
5475
+ if (tagName === "input" || tagName === "textarea" || tagName === "button" || tagName === "select" || target.isContentEditable || target.getAttribute("contenteditable") === "true") {
5476
+ return;
5477
+ }
5478
+ const interactiveParent = target.closest("input, textarea, button, select, [contenteditable], label");
5479
+ if (interactiveParent) {
5480
+ if (interactiveParent.tagName.toLowerCase() === "label") {
5481
+ const label = interactiveParent;
5482
+ if (label.control) {
5483
+ return;
5484
+ }
5485
+ } else {
5486
+ return;
5487
+ }
5488
+ }
5489
+ const anchor = target.closest("a[href]");
5490
+ if (!anchor) return;
5491
+ const href = anchor.getAttribute("href");
5492
+ if (!href) return;
5493
+ if (href.startsWith("#")) return;
5494
+ const url = new URL(href, window.location.href);
5495
+ if (url.origin !== window.location.origin) return;
5496
+ if (anchor.target && anchor.target !== "_self") return;
5497
+ ev.preventDefault();
5498
+ const nextUrl = url.pathname + url.search;
5499
+ const currentUrl = window.location.pathname + window.location.search;
5500
+ if (nextUrl === currentUrl) return;
5501
+ const shouldRevalidate = anchor.hasAttribute("data-revalidate") && anchor.getAttribute("data-revalidate") !== "false";
5502
+ window.history.pushState({}, "", nextUrl);
5503
+ navigate2(nextUrl, shouldRevalidate ? { revalidate: true } : void 0);
5504
+ } catch (error) {
5505
+ console.error("[navigation] Error in click handler:", error);
5506
+ }
5480
5507
  };
5481
5508
  }
5482
5509
  function createPopStateHandler(navigate2) {
@@ -5495,25 +5522,36 @@ function AppShell({
5495
5522
  errorRoute
5496
5523
  }) {
5497
5524
  const [state, setState] = useState(initialState);
5525
+ const handlersRef = useRef({
5526
+ setState,
5527
+ routes,
5528
+ notFoundRoute,
5529
+ errorRoute
5530
+ });
5498
5531
  useEffect(() => {
5499
- const handlers = {
5532
+ handlersRef.current = {
5500
5533
  setState,
5501
5534
  routes,
5502
5535
  notFoundRoute,
5503
5536
  errorRoute
5504
5537
  };
5538
+ }, [routes, notFoundRoute, errorRoute]);
5539
+ useEffect(() => {
5540
+ let isMounted = true;
5505
5541
  async function handleNavigate(nextUrl, options) {
5506
- await navigate(nextUrl, handlers, options);
5542
+ if (!isMounted) return;
5543
+ await navigate(nextUrl, handlersRef.current, options);
5507
5544
  }
5508
5545
  const handleClick = createClickHandler(handleNavigate);
5509
5546
  const handlePopState = createPopStateHandler(handleNavigate);
5510
- window.addEventListener("click", handleClick);
5511
- window.addEventListener("popstate", handlePopState);
5547
+ window.addEventListener("click", handleClick, false);
5548
+ window.addEventListener("popstate", handlePopState, false);
5512
5549
  return () => {
5513
- window.removeEventListener("click", handleClick);
5514
- window.removeEventListener("popstate", handlePopState);
5550
+ isMounted = false;
5551
+ window.removeEventListener("click", handleClick, false);
5552
+ window.removeEventListener("popstate", handlePopState, false);
5515
5553
  };
5516
- }, [routes, notFoundRoute, errorRoute]);
5554
+ }, []);
5517
5555
  const isError = state.route === errorRoute;
5518
5556
  const isNotFound = state.route === notFoundRoute;
5519
5557
  const routeType = isError ? "error" : isNotFound ? "notfound" : "normal";