one
Version:
One is a new React Framework that makes Vite serve both native and web.
1 lines • 3.35 kB
Source Map (JSON)
{"version":3,"names":["useRef","getServerContext","getQueryKey","resolveZeroQuery","useQuery","useQuery$1","clientInitialData","postRenderData","serverQueryData","globalThis","promises","WeakMap","query","enable","snapshot","queryIdRef","current","queryId","window","promise","get","value","promise2","Promise","res","rej","then","val","catch","err","set"],"sources":["useQuery.mjs"],"sourcesContent":["import { useRef } from \"react\";\nimport { getServerContext } from \"../vite/one-server-only\";\nimport { getQueryKey } from \"./getQueryKey\";\nimport { resolveZeroQuery } from \"./resolveQuery\";\nimport { useQuery as useQuery$1 } from \"./useQueryZero\";\n\nconst clientInitialData = getServerContext()?.postRenderData;\nconst serverQueryData = {};\nglobalThis[\"__vxrnServerData__\"] = serverQueryData;\nconst promises = /* @__PURE__ */ new WeakMap();\nconst useQuery = ((query, enable = true) => {\n\tconst snapshot = useQuery$1(query, enable);\n\tconst queryIdRef = useRef(void 0);\n\tif (query && !queryIdRef.current) queryIdRef.current = getQueryKey(query);\n\tconst queryId = queryIdRef.current || \"\";\n\tif (typeof window === \"undefined\") {\n\t\tif (!query) return [];\n\t\tconst promise = promises.get(query);\n\t\tconst value = serverQueryData[queryId];\n\t\tif (value) return value;\n\t\tif (!promise) {\n\t\t\tconst promise2 = new Promise((res, rej) => {\n\t\t\t\tresolveZeroQuery(query).then((val) => {\n\t\t\t\t\tserverQueryData[queryId] = val;\n\t\t\t\t\tres();\n\t\t\t\t}).catch((err) => {\n\t\t\t\t\tpromises.set(query, null);\n\t\t\t\t\trej(err);\n\t\t\t\t});\n\t\t\t});\n\t\t\tpromises.set(query, promise2);\n\t\t\tthrow promise2;\n\t\t}\n\t\tif (promise) throw promise;\n\t\treturn [];\n\t}\n\tif (clientInitialData && !snapshot) return clientInitialData[queryId] || [];\n\treturn snapshot || [];\n});\n\nexport { useQuery };"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,gBAAgB,QAAQ,6BAAyB;AAC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