Files
jp 0917366cdf Separate JSON API backend (vm_api.py) + React+TanStack frontend scaffold
- vm_api.py: pure FastAPI JSON API on :8098 with CORS
- vm-api.service: systemd unit for API (replaces inline HTML vm_web.py for frontend)
- vm_web.py: kept intact as fallback; Apache now proxies /api/ -> :8098
- frontend/: Vite + React + TanStack Query scaffold
- Apache vhost updated: DocumentRoot -> frontend/dist, /api/ proxy, SPA fallback
- All original HTML pages still functional via :8099 during transition
2026-08-13 17:42:33 +01:00

67 lines
2.2 KiB
JavaScript

"use client";
import { useLayoutEffect } from "./utils.js";
import { useRouter } from "./useRouter.js";
import { getLocationChangeInfo, trimPathRight } from "@tanstack/router-core";
import * as React$1 from "react";
//#region src/Transitioner.tsx
function settleOwner(owner, rendered) {
const settle = owner[1];
owner.length = 0;
settle?.(rendered);
}
function Transitioner({ t }) {
const router = useRouter();
const acknowledgement = router._rendered ??= [];
const mounted = process.env.NODE_ENV !== "production" ? React$1.useRef(false) : void 0;
router.startTransition = (fn, expected) => new Promise((resolve, reject) => {
settleOwner(acknowledgement, false);
acknowledgement.push(expected, resolve);
t(router);
React$1.startTransition(() => {
try {
fn();
} catch (cause) {
if (acknowledgement[1] === resolve) acknowledgement.length = 0;
reject(cause);
}
});
});
if (process.env.NODE_ENV !== "production") router._cancelTransition = () => settleOwner(acknowledgement, false);
useLayoutEffect(() => {
const unsub = router.history.subscribe(router.load);
if (mounted?.current) return unsub;
if (mounted) mounted.current = true;
router.updateLatestLocation();
const location = router.latestLocation;
const nextLocation = router.buildLocation({
to: location.pathname,
search: true,
params: true,
hash: true,
state: true,
_includeValidateSearch: true
});
if (trimPathRight(location.publicHref) !== trimPathRight(nextLocation.publicHref)) {
router.commitLocation({
...nextLocation,
replace: true,
ignoreBlocker: true
});
return unsub;
}
const resolvedLocation = router.stores.resolvedLocation.get();
if (resolvedLocation?.href === location.href && resolvedLocation.state.__TSR_key === location.state.__TSR_key) acknowledgement.push(router.stores.matches.get(), (rendered) => {
if (rendered) router.emit({
type: "onRendered",
...getLocationChangeInfo(resolvedLocation, resolvedLocation)
});
});
else if (!router._tx) router.load().catch(console.error);
return unsub;
}, [router, router.history]);
return null;
}
//#endregion
export { Transitioner, settleOwner };
//# sourceMappingURL=Transitioner.js.map