@backtickjs/hono 0.3.1 → 0.4.0
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/runtime.d.ts +9 -4
- package/dist/runtime.js +11 -13
- package/dist/runtime.js.map +1 -1
- package/package.json +8 -8
- package/src/runtime.tsx +205 -158
package/dist/runtime.d.ts
CHANGED
|
@@ -33,14 +33,19 @@ export interface Runtime {
|
|
|
33
33
|
/**
|
|
34
34
|
* Fetches an href ahead, as Next.js's `Link` prefetches: its layouts down
|
|
35
35
|
* to its first loading state, and that loading state (nothing if it has
|
|
36
|
-
* none)
|
|
36
|
+
* none), as Next.js's `kind: "auto"`; with `kind: "full"`, its page too,
|
|
37
|
+
* as `<Link prefetch>`. At most 4 run at a time, `urgent` ones (a pressed
|
|
38
|
+
* link) first. Returns a cancel, for a link that goes away before its
|
|
39
|
+
* turn.
|
|
37
40
|
*/
|
|
38
|
-
prefetch?(href: string,
|
|
41
|
+
prefetch?(href: string, options?: {
|
|
42
|
+
kind?: "auto" | "full";
|
|
43
|
+
urgent?: boolean;
|
|
44
|
+
}): () => void;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* A route's answer, run. Any bundle is an answer, whatever its status: an
|
|
42
|
-
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
43
|
-
* a route that may not exist (`notFoundIsNull`), a 404 is null.
|
|
48
|
+
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
44
49
|
*/
|
|
45
50
|
export declare const fetchAnswer: Client<unknown>;
|
|
46
51
|
/**
|
package/dist/runtime.js
CHANGED
|
@@ -3,34 +3,32 @@
|
|
|
3
3
|
// `/.well-known/backtick/runtime`.
|
|
4
4
|
import { cs, exec } from "@backtickjs/core";
|
|
5
5
|
const QueryClient = { "@backtickjs": "ClientImport", name: "QueryClient", from: "@tanstack/react-query", version: "5.104.0" };
|
|
6
|
-
const
|
|
6
|
+
const queryOptions = { "@backtickjs": "ClientImport", name: "queryOptions", from: "@tanstack/react-query", version: "5.104.0" };
|
|
7
7
|
const usePrefetchQuery = { "@backtickjs": "ClientImport", name: "usePrefetchQuery", from: "@tanstack/react-query", version: "5.104.0" };
|
|
8
|
-
const useSuspenseQueries = { "@backtickjs": "ClientImport", name: "useSuspenseQueries", from: "@tanstack/react-query", version: "5.104.0" };
|
|
9
8
|
const useSuspenseQuery = { "@backtickjs": "ClientImport", name: "useSuspenseQuery", from: "@tanstack/react-query", version: "5.104.0" };
|
|
10
9
|
const PatternRouter = { "@backtickjs": "ClientImport", name: "PatternRouter", from: "hono/router/pattern-router", version: "4.13.13" };
|
|
11
|
-
const Component = { "@backtickjs": "ClientImport", name: "Component", from: "react", version: "19.3.0" };
|
|
12
10
|
const Suspense = { "@backtickjs": "ClientImport", name: "Suspense", from: "react", version: "19.3.0" };
|
|
11
|
+
const use = { "@backtickjs": "ClientImport", name: "use", from: "react", version: "19.3.0" };
|
|
13
12
|
const useDeferredValue = { "@backtickjs": "ClientImport", name: "useDeferredValue", from: "react", version: "19.3.0" };
|
|
14
13
|
const $module0 = {
|
|
15
|
-
id: "
|
|
16
|
-
code: "(module, exports, require) => {\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = $splice0 => async (url, modules
|
|
17
|
-
map: "{\"version\":3,\"file\":\"module.jsx\",\"mappings\":\";;;
|
|
14
|
+
id: "1nni9w5x4wwcx:65:27",
|
|
15
|
+
code: "(module, exports, require) => {\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = $splice0 => async (url, modules) => {\n var aborter = new AbortController();\n var timer = setTimeout(() => aborter.abort(), 15000);\n var response = await fetch(url, {\n headers: {\n \"x-backtick-modules\": modules\n },\n signal: aborter.signal\n }).finally(() => clearTimeout(timer));\n var body = await response.text();\n if (!(response.headers.get(\"content-type\") ?? \"\").startsWith(\"text/javascript\")) {\n var reason = body;\n try {\n reason = JSON.parse(body).message ?? body;\n }\n catch { }\n throw new Error(\"The screen couldn't be opened (\" + response.status + \"): \" + reason);\n }\n return await $splice0()(body);\n};\n}",
|
|
16
|
+
map: "{\"version\":3,\"file\":\"module.jsx\",\"mappings\":\";;;kBAgE8BA,QAAA,WAAOC,GAAW,EAAEC,OAAe;IAI/D,IAAMC,OAAO,GAAG,IAAIC,eAAe,EAAE;IACrC,IAAMC,KAAK,GAAGC,UAAU,CAAC,MAAMH,OAAO,CAACI,KAAK,EAAE,EAAE,KAAK,CAAC;IACtD,IAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACR,GAAG,EAAE;QAChCS,OAAO,EAAE;YAAE,oBAAoB,EAAER;SAAS;QAC1CS,MAAM,EAAER,OAAO,CAACQ;KACjB,CAAC,CAACC,OAAO,CAAC,MAAMC,YAAY,CAACR,KAAK,CAAC,CAAC;IACrC,IAAMS,IAAI,GAAG,MAAMN,QAAQ,CAACO,IAAI,EAAE;IAClC,IACE,CAAC,CAACP,QAAQ,CAACE,OAAO,CAACM,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,EAAEC,UAAU,CAAC,iBAAiB,CAAC,EAC3E;QACA,IAAIC,MAAM,GAAGJ,IAAI;QACjB,IAAI;YACFI,MAAM,GAAGC,IAAI,CAACC,KAAK,CAACN,IAAI,CAAC,CAACO,OAAO,IAAIP,IAAI;QAC3C,CAAC;QAAC,MAAM,CAAC;QACT,MAAM,IAAIQ,KAAK,CACb,iCAAiC,GAAGd,QAAQ,CAACe,MAAM,GAAG,KAAK,GAAGL,MAAM,CACrE;IACH;IACA,OAAQ,MAAMlB,QAAA,EAAK,CAACc,IAAa,CAAC;AACpC,CAAC\",\"names\":[\"$splice0\",\"url\",\"modules\",\"aborter\",\"AbortController\",\"timer\",\"setTimeout\",\"abort\",\"response\",\"fetch\",\"headers\",\"signal\",\"finally\",\"clearTimeout\",\"body\",\"text\",\"get\",\"startsWith\",\"reason\",\"JSON\",\"parse\",\"message\",\"Error\",\"status\"],\"ignoreList\":[],\"sources\":[\"@backtickjs/hono/src/runtime.tsx\"]}",
|
|
18
17
|
dependencies: [],
|
|
19
18
|
params: [{ kind: "splice", bindings: [] }],
|
|
20
19
|
kind: "function"
|
|
21
20
|
};
|
|
22
21
|
const $module1 = {
|
|
23
|
-
id: "
|
|
24
|
-
code: "(module, exports, require) => {\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst jsx_runtime_1 = require(\"react/jsx-runtime\");\nexports.default = ($splice0, $splice1, $splice2, $splice3, $splice4, $splice5, $splice6, $splice7, $splice8, $splice9, $splice10, $splice11, $splice12, $splice13, $splice14, $splice15, $splice16, $splice17, $splice18, $splice19
|
|
25
|
-
map: "{\"version\":3,\"file\":\"module.jsx\",\"mappings\":\";;;;kBAgGY,CAAAA,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA;IAMR,IAAMC,gBAAgB,GAAG,MAAM;IAG/B,IAAIC,iBAAiB,GAAG;QAAEC,IAAI,EAAE,EAAE;QAAEC,SAAS,EAAE;KAAG;IAClD,IAAMC,YAAY,GAAG,IAAIC,GAAG,EAAU;IACtC,IAAMC,aAAa,GAAIC,KAGtB,IACCA,KAAK,CAACC,KAAK,CAACC,aAAa,IAAIR,iBAAiB,CAACE,SAAS,GACpDO,QAAQ,GACRN,YAAY,CAACO,GAAG,CAACJ,KAAK,CAACK,QAAQ,CAAC,CAAC,CAAW,CAAC,GAC3CZ,gBAAgB,GAChB,CAAC;IACT,IAAMa,WAAW,GAAG,KAAIpC,QAAA,EAAY,EAAC;QACnCqC,cAAc,EAAE;YACdC,OAAO,EAAE;gBACPC,OAAO,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CAClE,CACF;QACH;KACD;IACD,OAAOyC,OAAO;AAChB,CAAC\",\"names\":[\"$splice0\",\"$splice1\",\"$splice2\",\"$splice3\",\"$splice4\",\"$splice5\",\"$splice6\",\"$splice7\",\"$splice8\",\"$splice9\",\"$splice10\",\"$splice11\",\"$splice12\",\"$splice13\",\"$splice14\",\"$splice15\",\"$splice16\",\"$splice17\",\"$splice18\",\"$splice19\",\"$splice20\",\"$splice21\",\"$splice22\",\"segmentStaleTime\",\"currentNavigation\",\"href\",\"startedAt\",\"fetchedAhead\",\"Set\",\"pageStaleTime\",\"query\",\"state\",\"dataUpdatedAt\",\"Infinity\",\"has\",\"queryKey\",\"queryClient\",\"defaultOptions\",\"queries\",\"queryFn\",\"context\",\"staleTime\",\"structuralSharing\",\"retry\",\"pageQuery\",\"layoutQuery\",\"path\",\"loadingQuery\",\"pattern\",\"value\",\"layoutRouter\",\"layouts\",\"add\",\"loadingRouter\",\"loadings\",\"segmentsOf\",\"searchStart\",\"indexOf\",\"slice\",\"names\",\"split\",\"filter\",\"Boolean\",\"bases\",\"map\",\"_\",\"i\",\"join\",\"base\",\"layout\",\"match\",\"length\",\"undefined\",\"loading\",\"shellOf\",\"segment\",\"push\",\"loads\",\"dropStaleAnswer\",\"cached\",\"getQueryCache\",\"find\",\"exact\",\"getObserversCount\",\"data\",\"isStaleByTime\",\"removeQueries\",\"Page\",\"props\",\"Loading\",\"Layout\",\"answer\",\"Answer\",\"_jsx\",\"children\",\"Segments\",\"node\",\"_loop\",\"$Suspense\",\"fallback\",\"reverse\",\"prefetch\",\"page\",\"shell\",\"catch\",\"Screen\",\"active\",\"AwaitQueries\",\"refetchOnMount\",\"NavigationHold\",\"Date\",\"now\",\"shown\",\"SilentErrorBoundary\",\"failed\",\"getDerivedStateFromError\",\"render\",\"RootLayout\",\"Error\",\"Navigator\",\"$QueryClientProvider\",\"_jsxs\",\"client\",\"runtime\",\"reload\",\"paths\",\"flatMap\",\"Promise\",\"allSettled\",\"getQueryState\",\"status\",\"resetQueries\",\"refetchQueries\"],\"ignoreList\":[],\"sources\":[\"@backtickjs/hono/src/runtime.tsx\"]}",
|
|
22
|
+
id: "1nni9w5x4wwcx:100:9",
|
|
23
|
+
code: "(module, exports, require) => {\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst jsx_runtime_1 = require(\"react/jsx-runtime\");\nexports.default = ($splice0, $splice1, $splice2, $splice3, $splice4, $splice5, $splice6, $splice7, $splice8, $splice9, $splice10, $splice11, $splice12, $splice13, $splice14, $splice15, $splice16, $splice17, $splice18, $splice19) => {\n var segmentStaleTime = 300000;\n var navigationStartedAt = 0;\n var fetchedAhead = new Map();\n var shown = query => query.getObserversCount() > 0;\n var segmentStale = query => shown(query) ? Infinity : segmentStaleTime;\n var pageStale = query => {\n var updatedAt = query.state.dataUpdatedAt;\n if (shown(query) || updatedAt >= navigationStartedAt) {\n return Infinity;\n }\n return fetchedAhead.get(query.queryKey[0]) === updatedAt ? segmentStaleTime : 0;\n };\n var fetchPath = path => () => $splice0()($splice1() + path, $splice2());\n var queryClient = new ($splice3())({\n defaultOptions: {\n queries: {\n structuralSharing: false,\n retry: false\n }\n }\n });\n var pageQuery = href => $splice4()({\n queryKey: [href],\n queryFn: fetchPath(href),\n staleTime: pageStale\n });\n var layoutQuery = path => $splice5()({\n queryKey: [path],\n queryFn: fetchPath(path),\n staleTime: segmentStale\n });\n var loadingQuery = pattern => $splice6()({\n queryKey: [pattern],\n queryFn: fetchPath(pattern),\n staleTime: segmentStale\n });\n var layoutRouter = new ($splice7())();\n for (var pattern of $splice8().layouts) {\n layoutRouter.add(\"GET\", pattern, pattern);\n }\n var loadingRouter = new ($splice9())();\n for (var _pattern of $splice10().loadings) {\n loadingRouter.add(\"GET\", _pattern, _pattern);\n }\n var segmentsOf = href => {\n var searchStart = href.indexOf(\"?\");\n var path = searchStart === -1 ? href : href.slice(0, searchStart);\n var names = path.split(\"/\").filter(Boolean);\n var bases = [\"\", ...names.map((_, i) => \"/\" + names.slice(0, i + 1).join(\"/\"))];\n return bases.map(base => {\n var layout = base + \"/_layout\";\n return {\n layout: base !== \"\" && layoutRouter.match(\"GET\", layout)[0].length > 0 ? layout : undefined,\n loading: loadingRouter.match(\"GET\", base + \"/_loading\")[0][0]?.[0]\n };\n });\n };\n var shellOf = href => {\n var queries = [];\n for (var segment of segmentsOf(href)) {\n if (segment.layout !== undefined) {\n queries.push(layoutQuery(segment.layout));\n }\n if (segment.loading !== undefined) {\n queries.push(loadingQuery(segment.loading));\n return {\n queries,\n loads: true\n };\n }\n }\n queries.push(pageQuery(href));\n return {\n queries,\n loads: false\n };\n };\n var Page = props => $splice11()(pageQuery(props.href), queryClient).data;\n var Loading = props => $splice12()(loadingQuery(props.pattern), queryClient).data;\n var Layout = props => {\n var answer = $splice13()(layoutQuery(props.path), queryClient).data;\n if (typeof answer !== \"function\") {\n return answer;\n }\n var Answer = answer;\n return (0, jsx_runtime_1.jsx)(Answer, {\n children: props.children\n });\n };\n var Segments = props => {\n $splice14()(pageQuery(props.href), queryClient);\n var node = (0, jsx_runtime_1.jsx)(Page, {\n href: props.href\n });\n var _loop = function (segment) {\n if (segment.loading !== undefined) {\n node = ($Suspense => (0, jsx_runtime_1.jsx)($Suspense, {\n fallback: (0, jsx_runtime_1.jsx)(Loading, {\n pattern: segment.loading\n }),\n children: node\n }))($splice15());\n }\n if (segment.layout !== undefined) {\n node = (0, jsx_runtime_1.jsx)(Layout, {\n path: segment.layout,\n children: node\n });\n }\n };\n for (var segment of segmentsOf(props.href).reverse()) {\n _loop(segment);\n }\n return node;\n };\n var maxPrefetches = 4;\n var prefetching = 0;\n var waiting = [];\n var startWaiting = () => {\n while (prefetching < maxPrefetches && waiting.length > 0) {\n waiting.shift()();\n }\n };\n var schedule = (task, urgent) => {\n var start = () => {\n prefetching += 1;\n void task().catch(() => { }).finally(() => {\n prefetching -= 1;\n startWaiting();\n });\n };\n if (urgent) {\n start();\n return () => { };\n }\n waiting.push(start);\n startWaiting();\n return () => {\n var index = waiting.indexOf(start);\n if (index !== -1) {\n waiting.splice(index, 1);\n }\n };\n };\n var prefetch = (href, options = {}) => {\n var full = options.kind === \"full\";\n var shell = shellOf(href);\n if (!full && !shell.loads) {\n return () => { };\n }\n return schedule(async () => {\n await Promise.all(shell.queries.map(query => queryClient.query(query)));\n if (full) {\n await queryClient.query(pageQuery(href));\n fetchedAhead.set(href, queryClient.getQueryState([href])?.dataUpdatedAt ?? 0);\n }\n }, options.urgent ?? false);\n };\n var Screen = props => {\n var href = $splice16()(props.href);\n return props.active ? ($Suspense => (0, jsx_runtime_1.jsx)($Suspense, {\n fallback: null,\n children: (0, jsx_runtime_1.jsx)(Segments, {\n href: href\n })\n }))($splice17()) : null;\n };\n var isIn = query => {\n var cached = queryClient.getQueryCache().find({\n queryKey: query.queryKey,\n exact: true\n });\n return cached !== undefined && cached.state.data !== undefined && !cached.isStaleByTime(query.staleTime(cached));\n };\n var hold;\n var NavigationHold = props => {\n if (hold?.href !== props.href) {\n navigationStartedAt = Date.now();\n var page = queryClient.getQueryCache().find({\n queryKey: [props.href],\n exact: true\n });\n if (page !== undefined && page.state.data !== undefined && page.isStaleByTime(pageStale(page))) {\n queryClient.removeQueries({\n queryKey: [props.href],\n exact: true\n });\n }\n var queries = shellOf(props.href).queries;\n hold = {\n href: props.href,\n ready: page !== undefined && shown(page) || queries.every(isIn) ? undefined : Promise.allSettled(queries.map(query => queryClient.query(query)))\n };\n void queryClient.query(pageQuery(props.href)).catch(() => { });\n }\n if (hold.ready !== undefined) {\n $splice18()(hold.ready);\n }\n return null;\n };\n var RootLayout = () => {\n var answer = $splice19()({\n queryKey: [\"/_layout\"],\n queryFn: fetchPath(\"/_layout\"),\n staleTime: Infinity\n }, queryClient).data;\n if (typeof answer !== \"function\") {\n throw new Error(\"The app's /_layout answers no component: it's the root layout, a client component drawing the navigator (a Stack).\");\n }\n var Answer = answer;\n return (0, jsx_runtime_1.jsx)(Answer, {});\n };\n var Navigator = props => (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {\n children: [(0, jsx_runtime_1.jsx)(NavigationHold, {\n href: props.href\n }), (0, jsx_runtime_1.jsx)(RootLayout, {})]\n });\n var runtime = {\n Navigator,\n Screen,\n prefetch,\n reload: async (href) => {\n var paths = [href, ...segmentsOf(href).flatMap(segment => [...(segment.layout === undefined ? [] : [segment.layout]), ...(segment.loading === undefined ? [] : [segment.loading])])];\n await Promise.allSettled(paths.map(path => queryClient.getQueryState([path])?.status === \"error\" ? queryClient.resetQueries({\n queryKey: [path],\n exact: true\n }) : queryClient.refetchQueries({\n queryKey: [path],\n exact: true\n })));\n }\n };\n return runtime;\n};\n}",
|
|
24
|
+
map: "{\"version\":3,\"file\":\"module.jsx\",\"mappings\":\";;;;kBAmGY,CAAAA,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,QAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,SAAA;IAOR,IAAMC,gBAAgB,GAAG,MAAM;IAG/B,IAAIC,mBAAmB,GAAG,CAAC;IAC3B,IAAMC,YAAY,GAAG,IAAIC,GAAG,EAAkB;IAM9C,IAAMC,KAAK,GAAIC,KAAa,IAAKA,KAAK,CAACC,iBAAiB,EAAE,GAAG,CAAC;IAC9D,IAAMC,YAAY,GAAIF,KAAa,IACjCD,KAAK,CAACC,KAAK,CAAC,GAAGG,QAAQ,GAAGR,gBAAgB;IAC5C,IAAMS,SAAS,GAAIJ,KAAa;QAC9B,IAAMK,SAAS,GAAGL,KAAK,CAACM,KAAK,CAACC,aAAa;QAC3C,IAAIR,KAAK,CAACC,KAAK,CAAC,IAAIK,SAAS,IAAIT,mBAAmB,EAAE;YACpD,OAAOO,QAAQ;QACjB;QACA,OA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,OAAO,GAAY;QACvBH,SAAS;QACTnB,MAAM;QACNT,QAAQ;QAIRgC,MAAM,EAAE,OAAO9F,IAAI;YACjB,IAAM+F,KAAK,GAAG,CACZ/F,IAAI,EACJ,GAAGW,UAAU,CAACX,IAAI,CAAC,CAACgG,OAAO,CAAEjE,OAAO,IAAK,CACvC,IAAIA,OAAO,CAACN,MAAM,KAAKG,SAAS,GAAG,EAAE,GAAG,CAACG,OAAO,CAACN,MAAM,CAAC,CAAC,EACzD,IAAIM,OAAO,CAACF,OAAO,KAAKD,SAAS,GAAG,EAAE,GAAG,CAACG,OAAO,CAACF,OAAO,CAAC,CAAC,CAC5D,CAAC,CACH;YACD,MAAMsC,OAAO,CAACoB,UAAU,CACtBQ,KAAK,CAAC3E,GAAG,CAAE3B,IAAI,IACbC,WAAW,CAAC4E,aAAa,CAAC,CAAC7E,IAAI,CAAC,CAAC,EAAEwG,MAAM,KAAK,OAAO,GACjDvG,WAAW,CAACwG,YAAY,CAAC;gBAAE3G,QAAQ,EAAE,CAACE,IAAI,CAAC;gBAAEoF,KAAK,EAAE;aAAM,CAAC,GAC3DnF,WAAW,CAACyG,cAAc,CAAC;gBAAE5G,QAAQ,EAAE,CAACE,IAAI,CAAC;gBAAEoF,KAAK,EAAE;aAAM,CAAC,CAClE,CACF;QACH;KACD;IACD,OAAOgB,OAAO;AAChB,CAAC\",\"names\":[\"$splice0\",\"$splice1\",\"$splice2\",\"$splice3\",\"$splice4\",\"$splice5\",\"$splice6\",\"$splice7\",\"$splice8\",\"$splice9\",\"$splice10\",\"$splice11\",\"$splice12\",\"$splice13\",\"$splice14\",\"$splice15\",\"$splice16\",\"$splice17\",\"$splice18\",\"$splice19\",\"segmentStaleTime\",\"navigationStartedAt\",\"fetchedAhead\",\"Map\",\"shown\",\"query\",\"getObserversCount\",\"segmentStale\",\"Infinity\",\"pageStale\",\"updatedAt\",\"state\",\"dataUpdatedAt\",\"get\",\"queryKey\",\"fetchPath\",\"path\",\"queryClient\",\"defaultOptions\",\"queries\",\"structuralSharing\",\"retry\",\"pageQuery\",\"href\",\"queryFn\",\"staleTime\",\"layoutQuery\",\"loadingQuery\",\"pattern\",\"layoutRouter\",\"layouts\",\"add\",\"loadingRouter\",\"loadings\",\"segmentsOf\",\"searchStart\",\"indexOf\",\"slice\",\"names\",\"split\",\"filter\",\"Boolean\",\"bases\",\"map\",\"_\",\"i\",\"join\",\"base\",\"layout\",\"match\",\"length\",\"undefined\",\"loading\",\"shellOf\",\"segment\",\"push\",\"loads\",\"Page\",\"props\",\"data\",\"Loading\",\"Layout\",\"answer\",\"Answer\",\"_jsx\",\"children\",\"Segments\",\"node\",\"_loop\",\"$Suspense\",\"fallback\",\"reverse\",\"maxPrefetches\",\"prefetching\",\"waiting\",\"startWaiting\",\"shift\",\"schedule\",\"task\",\"urgent\",\"start\",\"catch\",\"finally\",\"index\",\"splice\",\"prefetch\",\"options\",\"full\",\"kind\",\"shell\",\"Promise\",\"all\",\"set\",\"getQueryState\",\"Screen\",\"active\",\"isIn\",\"cached\",\"getQueryCache\",\"find\",\"exact\",\"isStaleByTime\",\"hold\",\"NavigationHold\",\"Date\",\"now\",\"page\",\"removeQueries\",\"ready\",\"every\",\"allSettled\",\"RootLayout\",\"Error\",\"Navigator\",\"_jsxs\",\"_Fragment\",\"runtime\",\"reload\",\"paths\",\"flatMap\",\"status\",\"resetQueries\",\"refetchQueries\"],\"ignoreList\":[],\"sources\":[\"@backtickjs/hono/src/runtime.tsx\"]}",
|
|
26
25
|
dependencies: ["react/jsx-runtime"],
|
|
27
|
-
params: [{ kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }
|
|
26
|
+
params: [{ kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }, { kind: "splice", bindings: [] }],
|
|
28
27
|
kind: "block"
|
|
29
28
|
};
|
|
30
29
|
/**
|
|
31
30
|
* A route's answer, run. Any bundle is an answer, whatever its status: an
|
|
32
|
-
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
33
|
-
* a route that may not exist (`notFoundIsNull`), a 404 is null.
|
|
31
|
+
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
34
32
|
*/
|
|
35
33
|
export const fetchAnswer = cs.create($module0, [exec]);
|
|
36
34
|
/**
|
|
@@ -39,6 +37,6 @@ export const fetchAnswer = cs.create($module0, [exec]);
|
|
|
39
37
|
* so a screen asks only for those it has.
|
|
40
38
|
*/
|
|
41
39
|
export function clientRuntime(origin, modules, routes) {
|
|
42
|
-
return cs.create($module1, [
|
|
40
|
+
return cs.create($module1, [fetchAnswer, origin, modules, QueryClient, queryOptions, queryOptions, queryOptions, PatternRouter, routes, PatternRouter, routes, useSuspenseQuery, useSuspenseQuery, useSuspenseQuery, usePrefetchQuery, Suspense, useDeferredValue, Suspense, use, useSuspenseQuery]);
|
|
43
41
|
}
|
|
44
42
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.tsx"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,mCAAmC;AACnC,OAAO,EAAe,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.tsx"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,mCAAmC;AACnC,OAAO,EAAe,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAyDzD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,8BAuBtB,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EACd,OAAe,EACf,MAAmE;IAEnE,qSA8UG;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backtickjs/hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Hono routes as Backtick screens: a route's answer is its server components, bundled for the client that asked",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"backtick",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@backtickjs/bundler": "0.
|
|
41
|
-
"@backtickjs/core": "0.
|
|
40
|
+
"@backtickjs/bundler": "0.4.0",
|
|
41
|
+
"@backtickjs/core": "0.4.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"hono": "^4.13.13"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@backtickjs/expo": "0.
|
|
48
|
-
"@backtickjs/jsx-react": "0.
|
|
49
|
-
"@backtickjs/prettier-plugin": "0.
|
|
50
|
-
"@backtickjs/tsc": "0.
|
|
51
|
-
"@backtickjs/tspatch-plugin": "0.
|
|
47
|
+
"@backtickjs/expo": "0.4.0",
|
|
48
|
+
"@backtickjs/jsx-react": "0.4.0",
|
|
49
|
+
"@backtickjs/prettier-plugin": "0.4.0",
|
|
50
|
+
"@backtickjs/tsc": "0.4.0",
|
|
51
|
+
"@backtickjs/tspatch-plugin": "0.4.0",
|
|
52
52
|
"@tanstack/react-query": "5.104.0",
|
|
53
53
|
"@types/react": "19.3.0",
|
|
54
54
|
"hono": "^4.13.13",
|
package/src/runtime.tsx
CHANGED
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
import { type Client, cs, exec } from "@backtickjs/core";
|
|
5
5
|
import {
|
|
6
6
|
QueryClient,
|
|
7
|
-
|
|
7
|
+
queryOptions,
|
|
8
8
|
usePrefetchQuery,
|
|
9
|
-
useSuspenseQueries,
|
|
10
9
|
useSuspenseQuery,
|
|
11
10
|
} from "@tanstack/react-query" with { backtick: "client" };
|
|
12
11
|
import { PatternRouter } from "hono/router/pattern-router" with {
|
|
13
12
|
backtick: "client",
|
|
14
13
|
};
|
|
15
14
|
import {
|
|
16
|
-
Component,
|
|
17
15
|
type ComponentType,
|
|
18
16
|
type ReactNode,
|
|
19
17
|
Suspense,
|
|
18
|
+
use,
|
|
20
19
|
useDeferredValue,
|
|
21
20
|
} from "react" with { backtick: "client" };
|
|
22
21
|
|
|
@@ -48,27 +47,31 @@ export interface Runtime {
|
|
|
48
47
|
/**
|
|
49
48
|
* Fetches an href ahead, as Next.js's `Link` prefetches: its layouts down
|
|
50
49
|
* to its first loading state, and that loading state (nothing if it has
|
|
51
|
-
* none)
|
|
50
|
+
* none), as Next.js's `kind: "auto"`; with `kind: "full"`, its page too,
|
|
51
|
+
* as `<Link prefetch>`. At most 4 run at a time, `urgent` ones (a pressed
|
|
52
|
+
* link) first. Returns a cancel, for a link that goes away before its
|
|
53
|
+
* turn.
|
|
52
54
|
*/
|
|
53
|
-
prefetch?(
|
|
55
|
+
prefetch?(
|
|
56
|
+
href: string,
|
|
57
|
+
options?: { kind?: "auto" | "full"; urgent?: boolean },
|
|
58
|
+
): () => void;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
/**
|
|
57
62
|
* A route's answer, run. Any bundle is an answer, whatever its status: an
|
|
58
|
-
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
59
|
-
* a route that may not exist (`notFoundIsNull`), a 404 is null.
|
|
63
|
+
* app's not-found screen is one. A refusal ({ name, message }) says why.
|
|
60
64
|
*/
|
|
61
|
-
export const fetchAnswer = cs`async (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
export const fetchAnswer = cs`async (url: string, modules: string) => {
|
|
66
|
+
// One that doesn't answer within 15 seconds fails, as a stalled
|
|
67
|
+
// connection would otherwise hold a navigation, or a prefetch's turn, for
|
|
68
|
+
// good.
|
|
69
|
+
const aborter = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => aborter.abort(), 15000);
|
|
66
71
|
const response = await fetch(url, {
|
|
67
72
|
headers: { "x-backtick-modules": modules },
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
73
|
+
signal: aborter.signal,
|
|
74
|
+
}).finally(() => clearTimeout(timer));
|
|
72
75
|
const body = await response.text();
|
|
73
76
|
if (
|
|
74
77
|
!(response.headers.get("content-type") ?? "").startsWith("text/javascript")
|
|
@@ -97,61 +100,65 @@ export function clientRuntime(
|
|
|
97
100
|
return cs`{
|
|
98
101
|
// Every answer is a query, keyed by where it was fetched, and reused in
|
|
99
102
|
// memory as Next.js's router cache does: a layout or a loading state for 5
|
|
100
|
-
// minutes; a page only for the navigation it was fetched for (0 s), or,
|
|
101
|
-
// ahead by <Link prefetch>, for 5 minutes.
|
|
102
|
-
//
|
|
103
|
+
// minutes; a page only for the navigation it was fetched for (0 s), or,
|
|
104
|
+
// fetched ahead by <Link prefetch>, for 5 minutes. What a screen shows
|
|
105
|
+
// never goes stale, so going back shows it as it was. A screen's no-store
|
|
106
|
+
// keeps it out of HTTP caches, not this one.
|
|
103
107
|
const segmentStaleTime = 300000;
|
|
104
|
-
// When the navigation
|
|
105
|
-
//
|
|
106
|
-
let
|
|
107
|
-
const fetchedAhead = new
|
|
108
|
-
|
|
108
|
+
// When the navigation under way started, and the answers <Link prefetch>
|
|
109
|
+
// fetched ahead (each href's, by when it came in).
|
|
110
|
+
let navigationStartedAt = 0;
|
|
111
|
+
const fetchedAhead = new Map<string, number>();
|
|
112
|
+
type Cached = {
|
|
109
113
|
queryKey: readonly unknown[];
|
|
110
114
|
state: { dataUpdatedAt: number };
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
getObserversCount(): number;
|
|
116
|
+
};
|
|
117
|
+
const shown = (query: Cached) => query.getObserversCount() > 0;
|
|
118
|
+
const segmentStale = (query: Cached) =>
|
|
119
|
+
shown(query) ? Infinity : segmentStaleTime;
|
|
120
|
+
const pageStale = (query: Cached) => {
|
|
121
|
+
const updatedAt = query.state.dataUpdatedAt;
|
|
122
|
+
if (shown(query) || updatedAt >= navigationStartedAt) {
|
|
123
|
+
return Infinity;
|
|
124
|
+
}
|
|
125
|
+
return fetchedAhead.get(query.queryKey[0] as string) === updatedAt
|
|
126
|
+
? segmentStaleTime
|
|
127
|
+
: 0;
|
|
128
|
+
};
|
|
129
|
+
const fetchPath = (path: string) => () =>
|
|
130
|
+
$fetchAnswer($origin + path, $modules);
|
|
117
131
|
const queryClient = new $QueryClient({
|
|
118
132
|
defaultOptions: {
|
|
119
|
-
queries: {
|
|
120
|
-
queryFn: async (context: { queryKey: readonly unknown[] }) =>
|
|
121
|
-
$fetchAnswer(
|
|
122
|
-
$origin + (context.queryKey[0] as string),
|
|
123
|
-
$modules,
|
|
124
|
-
false,
|
|
125
|
-
),
|
|
126
|
-
staleTime: pageStaleTime,
|
|
127
|
-
structuralSharing: false,
|
|
128
|
-
retry: false,
|
|
129
|
-
},
|
|
133
|
+
queries: { structuralSharing: false, retry: false },
|
|
130
134
|
},
|
|
131
135
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
const pageQuery = (href: string) =>
|
|
137
|
+
$queryOptions({
|
|
138
|
+
queryKey: [href],
|
|
139
|
+
queryFn: fetchPath(href),
|
|
140
|
+
staleTime: pageStale,
|
|
141
|
+
});
|
|
142
|
+
// A layout answers a client component, given what's under it; or, for a
|
|
143
|
+
// path with none (its not-found screen), what the screen shows.
|
|
144
|
+
const layoutQuery = (path: string) =>
|
|
145
|
+
$queryOptions({
|
|
146
|
+
queryKey: [path],
|
|
147
|
+
queryFn: fetchPath(path),
|
|
148
|
+
staleTime: segmentStale,
|
|
149
|
+
});
|
|
142
150
|
// A loading state takes no params, as in Next.js: it's fetched at its
|
|
143
151
|
// pattern (/city/:id/_loading), once for every href it applies to.
|
|
144
|
-
const loadingQuery = (pattern: string) =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
152
|
+
const loadingQuery = (pattern: string) =>
|
|
153
|
+
$queryOptions({
|
|
154
|
+
queryKey: [pattern],
|
|
155
|
+
queryFn: fetchPath(pattern),
|
|
156
|
+
staleTime: segmentStale,
|
|
157
|
+
});
|
|
158
|
+
type Query =
|
|
159
|
+
| ReturnType<typeof pageQuery>
|
|
160
|
+
| ReturnType<typeof layoutQuery>
|
|
161
|
+
| ReturnType<typeof loadingQuery>;
|
|
155
162
|
|
|
156
163
|
// The app's layouts and loading states, matched by Hono's own router.
|
|
157
164
|
const layoutRouter = new $PatternRouter<string>();
|
|
@@ -201,33 +208,17 @@ export function clientRuntime(
|
|
|
201
208
|
queries.push(pageQuery(href));
|
|
202
209
|
return { queries, loads: false };
|
|
203
210
|
};
|
|
204
|
-
// A
|
|
205
|
-
// dropped as the navigation reads it, so the navigation waits for a fresh
|
|
206
|
-
// one, as Next.js's does; one a screen still shows, going back to it, is
|
|
207
|
-
// kept.
|
|
208
|
-
const dropStaleAnswer = (query: Query, startedAt: number) => {
|
|
209
|
-
const cached = queryClient
|
|
210
|
-
.getQueryCache()
|
|
211
|
-
.find({ queryKey: query.queryKey, exact: true });
|
|
212
|
-
if (
|
|
213
|
-
cached !== undefined &&
|
|
214
|
-
cached.getObserversCount() === 0 &&
|
|
215
|
-
cached.state.data !== undefined &&
|
|
216
|
-
cached.state.dataUpdatedAt < startedAt &&
|
|
217
|
-
cached.isStaleByTime(query.staleTime ?? pageStaleTime(cached))
|
|
218
|
-
) {
|
|
219
|
-
queryClient.removeQueries({ queryKey: query.queryKey, exact: true });
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
211
|
+
// A page or a loading state answers what it draws.
|
|
223
212
|
const Page = (props: { href: string }) =>
|
|
224
|
-
$useSuspenseQuery(pageQuery(props.href)).data as ReactNode;
|
|
213
|
+
$useSuspenseQuery(pageQuery(props.href), queryClient).data as ReactNode;
|
|
225
214
|
const Loading = (props: { pattern: string }) =>
|
|
226
|
-
$useSuspenseQuery(loadingQuery(props.pattern))
|
|
227
|
-
|
|
228
|
-
// answer (its not-found screen) is what the screen shows.
|
|
215
|
+
$useSuspenseQuery(loadingQuery(props.pattern), queryClient)
|
|
216
|
+
.data as ReactNode;
|
|
229
217
|
const Layout = (props: { path: string; children: ReactNode }) => {
|
|
230
|
-
const answer = $useSuspenseQuery(
|
|
218
|
+
const answer = $useSuspenseQuery(
|
|
219
|
+
layoutQuery(props.path),
|
|
220
|
+
queryClient,
|
|
221
|
+
).data;
|
|
231
222
|
if (typeof answer !== "function") {
|
|
232
223
|
return answer as ReactNode;
|
|
233
224
|
}
|
|
@@ -238,7 +229,7 @@ export function clientRuntime(
|
|
|
238
229
|
// Suspense showing its loading state, around what's under it. The page
|
|
239
230
|
// is fetched meanwhile.
|
|
240
231
|
const Segments = (props: { href: string }) => {
|
|
241
|
-
$usePrefetchQuery(pageQuery(props.href));
|
|
232
|
+
$usePrefetchQuery(pageQuery(props.href), queryClient);
|
|
242
233
|
let node: ReactNode = <Page href={props.href} />;
|
|
243
234
|
for (const segment of segmentsOf(props.href).reverse()) {
|
|
244
235
|
if (segment.loading !== undefined) {
|
|
@@ -255,27 +246,67 @@ export function clientRuntime(
|
|
|
255
246
|
return node;
|
|
256
247
|
};
|
|
257
248
|
|
|
249
|
+
// Prefetches run at most 4 at a time, as Next.js's: one whose link goes
|
|
250
|
+
// away before its turn is dropped, and an urgent one (a pressed link)
|
|
251
|
+
// starts at once, past the limit. query() fetches only what isn't in, or
|
|
252
|
+
// on its way, when a turn comes.
|
|
253
|
+
const maxPrefetches = 4;
|
|
254
|
+
let prefetching = 0;
|
|
255
|
+
const waiting: (() => void)[] = [];
|
|
256
|
+
const startWaiting = () => {
|
|
257
|
+
while (prefetching < maxPrefetches && waiting.length > 0) {
|
|
258
|
+
waiting.shift()!();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const schedule = (task: () => Promise<unknown>, urgent: boolean) => {
|
|
262
|
+
const start = () => {
|
|
263
|
+
prefetching += 1;
|
|
264
|
+
void task()
|
|
265
|
+
.catch(() => {})
|
|
266
|
+
.finally(() => {
|
|
267
|
+
prefetching -= 1;
|
|
268
|
+
startWaiting();
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
if (urgent) {
|
|
272
|
+
start();
|
|
273
|
+
return () => {};
|
|
274
|
+
}
|
|
275
|
+
waiting.push(start);
|
|
276
|
+
startWaiting();
|
|
277
|
+
return () => {
|
|
278
|
+
const index = waiting.indexOf(start);
|
|
279
|
+
if (index !== -1) {
|
|
280
|
+
waiting.splice(index, 1);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
258
285
|
// Fetches an href ahead, as Next.js's Link: what its screen needs to
|
|
259
|
-
// show, if that ends at a loading state, and its page too
|
|
260
|
-
// (<Link prefetch>).
|
|
261
|
-
const prefetch = (
|
|
286
|
+
// show, if that ends at a loading state ("auto"), and its page too
|
|
287
|
+
// ("full", <Link prefetch>), whose answer is then kept 5 minutes.
|
|
288
|
+
const prefetch = (
|
|
289
|
+
href: string,
|
|
290
|
+
options: { kind?: "auto" | "full"; urgent?: boolean } = {},
|
|
291
|
+
) => {
|
|
292
|
+
const full = options.kind === "full";
|
|
262
293
|
const shell = shellOf(href);
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
const queries = page
|
|
267
|
-
? [...shell.queries, pageQuery(href)]
|
|
268
|
-
: shell.loads
|
|
269
|
-
? shell.queries
|
|
270
|
-
: [];
|
|
271
|
-
for (const query of queries) {
|
|
272
|
-
void queryClient.query(query).catch(() => {});
|
|
294
|
+
if (!full && !shell.loads) {
|
|
295
|
+
return () => {};
|
|
273
296
|
}
|
|
297
|
+
return schedule(async () => {
|
|
298
|
+
await Promise.all(
|
|
299
|
+
shell.queries.map((query) => queryClient.query(query)),
|
|
300
|
+
);
|
|
301
|
+
if (full) {
|
|
302
|
+
await queryClient.query(pageQuery(href));
|
|
303
|
+
fetchedAhead.set(
|
|
304
|
+
href,
|
|
305
|
+
queryClient.getQueryState([href])?.dataUpdatedAt ?? 0,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}, options.urgent ?? false);
|
|
274
309
|
};
|
|
275
|
-
// Every loading state, as the app opens: one per pattern, for any href.
|
|
276
|
-
for (const pattern of $routes.loadings) {
|
|
277
|
-
void queryClient.query(loadingQuery(pattern)).catch(() => {});
|
|
278
|
-
}
|
|
279
310
|
|
|
280
311
|
// An href changed in place (router.setParams) shows once it's in: the
|
|
281
312
|
// screen stays meanwhile.
|
|
@@ -288,61 +319,75 @@ export function clientRuntime(
|
|
|
288
319
|
) : null;
|
|
289
320
|
};
|
|
290
321
|
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
322
|
+
// A query whose answer is in and fresh: nothing to wait for.
|
|
323
|
+
const isIn = (query: Query) => {
|
|
324
|
+
const cached = queryClient
|
|
325
|
+
.getQueryCache()
|
|
326
|
+
.find({ queryKey: query.queryKey, exact: true });
|
|
327
|
+
return (
|
|
328
|
+
cached !== undefined &&
|
|
329
|
+
cached.state.data !== undefined &&
|
|
330
|
+
!cached.isStaleByTime(
|
|
331
|
+
(query.staleTime as (cached: Cached) => number)(cached),
|
|
332
|
+
)
|
|
333
|
+
);
|
|
301
334
|
};
|
|
335
|
+
// The navigation on top, and what it waits for, if anything: kept
|
|
336
|
+
// outside React, as a render that suspends keeps no state.
|
|
337
|
+
let hold: { href: string; ready?: Promise<unknown> } | undefined;
|
|
302
338
|
// Suspends a navigation's render, above the Stack, until the href's
|
|
303
|
-
// screen can show (shellOf)
|
|
304
|
-
//
|
|
305
|
-
// the hold, for the
|
|
339
|
+
// screen can show (shellOf), fetching whatever of it isn't in, stale or
|
|
340
|
+
// failed; the page alongside. As navigations are transitions, the screen
|
|
341
|
+
// on top stays meanwhile. One that fails ends the hold too, for the
|
|
342
|
+
// screen to show why.
|
|
306
343
|
const NavigationHold = (props: { href: string }) => {
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
dropStaleAnswer(query, currentNavigation.startedAt);
|
|
313
|
-
}
|
|
314
|
-
// Going back, the screen shows its page as it was: only a page no
|
|
315
|
-
// screen shows is fetched.
|
|
316
|
-
const shown =
|
|
317
|
-
(queryClient
|
|
344
|
+
if (hold?.href !== props.href) {
|
|
345
|
+
navigationStartedAt = Date.now();
|
|
346
|
+
// A page from before, which no screen shows, would show as it was:
|
|
347
|
+
// dropped, so the screen shows its loading state, then the page.
|
|
348
|
+
const page = queryClient
|
|
318
349
|
.getQueryCache()
|
|
319
|
-
.find({ queryKey: [props.href], exact: true })
|
|
320
|
-
|
|
321
|
-
|
|
350
|
+
.find({ queryKey: [props.href], exact: true });
|
|
351
|
+
if (
|
|
352
|
+
page !== undefined &&
|
|
353
|
+
page.state.data !== undefined &&
|
|
354
|
+
page.isStaleByTime(pageStale(page))
|
|
355
|
+
) {
|
|
356
|
+
queryClient.removeQueries({ queryKey: [props.href], exact: true });
|
|
357
|
+
}
|
|
358
|
+
// Only a navigation with something to fetch suspends. Going back,
|
|
359
|
+
// to a page a screen still shows, renders at once, however old its
|
|
360
|
+
// shell: it's no transition, so a suspension would reach the app's
|
|
361
|
+
// own Suspense.
|
|
362
|
+
const queries = shellOf(props.href).queries;
|
|
363
|
+
hold = {
|
|
364
|
+
href: props.href,
|
|
365
|
+
ready:
|
|
366
|
+
(page !== undefined && shown(page)) || queries.every(isIn)
|
|
367
|
+
? undefined
|
|
368
|
+
: Promise.allSettled(
|
|
369
|
+
queries.map((query) => queryClient.query(query)),
|
|
370
|
+
),
|
|
371
|
+
};
|
|
322
372
|
void queryClient.query(pageQuery(props.href)).catch(() => {});
|
|
323
373
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
class SilentErrorBoundary extends $Component<
|
|
327
|
-
{ children: ReactNode },
|
|
328
|
-
{ failed: boolean }
|
|
329
|
-
> {
|
|
330
|
-
state = { failed: false };
|
|
331
|
-
static getDerivedStateFromError() {
|
|
332
|
-
return { failed: true };
|
|
333
|
-
}
|
|
334
|
-
render() {
|
|
335
|
-
return this.state.failed ? null : this.props.children;
|
|
374
|
+
if (hold.ready !== undefined) {
|
|
375
|
+
$use(hold.ready);
|
|
336
376
|
}
|
|
337
|
-
|
|
377
|
+
return null;
|
|
378
|
+
};
|
|
338
379
|
|
|
339
380
|
// The root layout, /_layout, which draws the navigator: fetched once per
|
|
340
381
|
// open, as a new one would remount the navigator, and its screens with it.
|
|
341
382
|
const RootLayout = () => {
|
|
342
|
-
const answer = $useSuspenseQuery(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
383
|
+
const answer = $useSuspenseQuery(
|
|
384
|
+
{
|
|
385
|
+
queryKey: ["/_layout"],
|
|
386
|
+
queryFn: fetchPath("/_layout"),
|
|
387
|
+
staleTime: Infinity,
|
|
388
|
+
},
|
|
389
|
+
queryClient,
|
|
390
|
+
).data;
|
|
346
391
|
if (typeof answer !== "function") {
|
|
347
392
|
throw new Error(
|
|
348
393
|
"The app's /_layout answers no component: it's the root layout, a client component drawing the navigator (a Stack).",
|
|
@@ -352,27 +397,29 @@ export function clientRuntime(
|
|
|
352
397
|
return <Answer />;
|
|
353
398
|
};
|
|
354
399
|
|
|
400
|
+
// The runtime's hooks name its client, so an app's own React Query, with
|
|
401
|
+
// or without a provider, never shares the runtime's cache.
|
|
355
402
|
const Navigator = (props: { href: string }) => (
|
|
356
|
-
|
|
357
|
-
<
|
|
358
|
-
<NavigationHold href={props.href} />
|
|
359
|
-
</SilentErrorBoundary>
|
|
403
|
+
<>
|
|
404
|
+
<NavigationHold href={props.href} />
|
|
360
405
|
<RootLayout />
|
|
361
|
-
|
|
406
|
+
</>
|
|
362
407
|
);
|
|
363
408
|
|
|
364
409
|
const runtime: Runtime = {
|
|
365
410
|
Navigator,
|
|
366
411
|
Screen,
|
|
367
412
|
prefetch,
|
|
368
|
-
// Its page and
|
|
369
|
-
// for it; the others kept until the new answer is
|
|
413
|
+
// Its page, layouts and loading states again: one that failed, for
|
|
414
|
+
// its screen to wait for it; the others kept until the new answer is
|
|
415
|
+
// in.
|
|
370
416
|
reload: async (href) => {
|
|
371
417
|
const paths = [
|
|
372
418
|
href,
|
|
373
|
-
...segmentsOf(href).flatMap((segment) =>
|
|
374
|
-
segment.layout === undefined ? [] : [segment.layout],
|
|
375
|
-
|
|
419
|
+
...segmentsOf(href).flatMap((segment) => [
|
|
420
|
+
...(segment.layout === undefined ? [] : [segment.layout]),
|
|
421
|
+
...(segment.loading === undefined ? [] : [segment.loading]),
|
|
422
|
+
]),
|
|
376
423
|
];
|
|
377
424
|
await Promise.allSettled(
|
|
378
425
|
paths.map((path) =>
|