@taujs/react 0.1.6 → 0.1.8

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.d.ts CHANGED
@@ -88,70 +88,4 @@ declare function createRenderer<T extends Record<string, unknown> = Record<strin
88
88
  };
89
89
  };
90
90
 
91
- /**
92
- * τjs Client Data Bridge
93
- *
94
- * Provides framework-agnostic primitives for accessing route data:
95
- * - SSR hydration (window.__INITIAL_DATA__)
96
- * - Client-side fetch (/__taujs/route endpoint)
97
- *
98
- * This is a transport layer only. For data orchestration (caching, refetch, etc.),
99
- * use TanStack Query or similar.
100
- */
101
- type RouteData = Record<string, unknown>;
102
- /**
103
- * Error thrown when fetchRouteData receives a non-2xx response.
104
- * Contains structured error information from the server.
105
- */
106
- declare class RouteDataError extends Error {
107
- readonly status: number;
108
- readonly statusText: string;
109
- readonly code?: string;
110
- readonly body?: unknown;
111
- constructor(message: string, opts: {
112
- status: number;
113
- statusText: string;
114
- code?: string;
115
- body?: unknown;
116
- });
117
- }
118
- /**
119
- * Read SSR boot data from window.__INITIAL_DATA__ exactly once.
120
- * Subsequent calls return null (forces client-side fetch).
121
- *
122
- * Returns null on server (typeof window === 'undefined').
123
- */
124
- declare function readInitialDataOnce<T extends RouteData = RouteData>(): T | null;
125
- /**
126
- * Fetch route data from the τjs data endpoint.
127
- *
128
- * Calls: GET /__taujs/route?url=<pathname>
129
- * Returns: { data: T }
130
- *
131
- * Throws RouteDataError on non-2xx responses with structured error info.
132
- *
133
- * @example
134
- * const data = await fetchRouteData('/app/dashboard');
135
- *
136
- * @example
137
- * try {
138
- * const data = await fetchRouteData('/app/dashboard');
139
- * } catch (err) {
140
- * if (err instanceof RouteDataError && err.status === 404) {
141
- * // Handle not found
142
- * }
143
- * }
144
- */
145
- declare function fetchRouteData<T extends RouteData = RouteData>(pathname: string, init?: RequestInit): Promise<T>;
146
- /**
147
- * Get the current browser path (pathname + search).
148
- * Does not include hash.
149
- *
150
- * Returns null on server (typeof window === 'undefined').
151
- *
152
- * @example
153
- * const path = getCurrentPath(); // "/app/dashboard?tab=overview"
154
- */
155
- declare function getCurrentPath(): string | null;
156
-
157
- export { type HeadContext, type HydrateAppOptions, type RenderCallbacks, type RouteData, RouteDataError, type SSRStore, SSRStoreProvider, type ServerLogs, type StreamOptions, createRenderer, createSSRStore, fetchRouteData, getCurrentPath, hydrateApp, readInitialDataOnce, useSSRStore };
91
+ export { type HeadContext, type HydrateAppOptions, type RenderCallbacks, type SSRStore, SSRStoreProvider, type ServerLogs, type StreamOptions, createRenderer, createSSRStore, hydrateApp, useSSRStore };
package/dist/index.js CHANGED
@@ -548,73 +548,10 @@ function createRenderer({
548
548
  };
549
549
  return { renderSSR, renderStream };
550
550
  }
551
-
552
- // src/RouteData.ts
553
- var RouteDataError = class _RouteDataError extends Error {
554
- status;
555
- statusText;
556
- code;
557
- body;
558
- constructor(message, opts) {
559
- super(message);
560
- this.name = "RouteDataError";
561
- this.status = opts.status;
562
- this.statusText = opts.statusText;
563
- this.code = opts.code;
564
- this.body = opts.body;
565
- Object.setPrototypeOf(this, _RouteDataError.prototype);
566
- }
567
- };
568
- var INITIAL_DATA_KEY = "__INITIAL_DATA__";
569
- function readInitialDataOnce() {
570
- if (typeof window === "undefined") return null;
571
- const w = window;
572
- const data = w[INITIAL_DATA_KEY];
573
- if (!data) return null;
574
- delete w[INITIAL_DATA_KEY];
575
- return data;
576
- }
577
- async function fetchRouteData(pathname, init) {
578
- if (!pathname) {
579
- throw new Error("fetchRouteData: pathname is required");
580
- }
581
- const url = `/__taujs/route?url=${encodeURIComponent(pathname)}`;
582
- const res = await fetch(url, {
583
- credentials: "include",
584
- ...init
585
- });
586
- if (!res.ok) {
587
- let body2;
588
- try {
589
- body2 = await res.json();
590
- } catch {
591
- const text = await res.text().catch(() => "");
592
- body2 = { error: text };
593
- }
594
- const json = body2;
595
- throw new RouteDataError(json.error ?? `Request failed: ${res.status}`, {
596
- status: res.status,
597
- statusText: json.statusText ?? res.statusText,
598
- code: json.code,
599
- body: body2
600
- });
601
- }
602
- const body = await res.json();
603
- return body.data ?? {};
604
- }
605
- function getCurrentPath() {
606
- if (typeof window === "undefined") return null;
607
- const { pathname, search } = window.location;
608
- return `${pathname}${search}`;
609
- }
610
551
  export {
611
- RouteDataError,
612
552
  SSRStoreProvider,
613
553
  createRenderer,
614
554
  createSSRStore,
615
- fetchRouteData,
616
- getCurrentPath,
617
555
  hydrateApp,
618
- readInitialDataOnce,
619
556
  useSSRStore
620
557
  };
package/dist/plugin.d.ts CHANGED
@@ -1,6 +1,17 @@
1
1
  import react from '@vitejs/plugin-react';
2
2
  import { PluginOption } from 'vite';
3
3
 
4
+ /**
5
+ * NOTE:
6
+ * `@vitejs/plugin-react` is a **peer dependency only**.
7
+ *
8
+ * It is intentionally NOT installed as a dependency to avoid
9
+ * coupling τjs to a specific Vite toolchain or React refresh implementation.
10
+ *
11
+ * Consumers using `@taujs/react/plugin` must install `@vitejs/plugin-react`
12
+ * in their own project.
13
+ */
14
+
4
15
  declare function pluginReact(opts?: Parameters<typeof react>[0]): PluginOption;
5
16
 
6
17
  export { pluginReact };
package/dist/plugin.js CHANGED
@@ -1,7 +1,22 @@
1
1
  // src/plugin.ts
2
2
  import react from "@vitejs/plugin-react";
3
+ function taujsReactPreambleFix() {
4
+ return {
5
+ name: "taujs:react-refresh-preamble-fix",
6
+ apply: "serve",
7
+ enforce: "post",
8
+ transformIndexHtml(html) {
9
+ if (html.includes("__vite_plugin_react_preamble_installed__")) return html;
10
+ if (!html.includes("/@react-refresh")) return html;
11
+ return html.replace(
12
+ /<head([^>]*)>/i,
13
+ `<head$1><script>window.__vite_plugin_react_preamble_installed__=true;window.$RefreshReg$=()=>{};window.$RefreshSig$=()=>(t)=>t;</script>`
14
+ );
15
+ }
16
+ };
17
+ }
3
18
  function pluginReact(opts) {
4
- return react(opts);
19
+ return [react(opts), taujsReactPreambleFix()];
5
20
  }
6
21
  export {
7
22
  pluginReact
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taujs/react",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "taujs | τjs",
5
5
  "author": "Aoede <taujs@aoede.uk.net> (https://www.aoede.uk.net)",
6
6
  "license": "MIT",
@@ -45,25 +45,25 @@
45
45
  "@testing-library/dom": "^10.4.0",
46
46
  "@testing-library/react": "^16.1.0",
47
47
  "@types/node": "^24.0.7",
48
- "@types/react": "^19.0.2",
49
- "@types/react-dom": "^19.0.2",
48
+ "@types/react": "^19.2.8",
49
+ "@types/react-dom": "^19.2.3",
50
50
  "@vitest/coverage-v8": "^3.2.4",
51
51
  "@vitest/ui": "^3.2.4",
52
52
  "jsdom": "^25.0.0",
53
53
  "prettier": "^3.3.3",
54
- "react": "^19.0.0",
55
- "react-dom": "^19.0.0",
54
+ "react": "^19.2.3",
55
+ "react-dom": "^19.2.3",
56
56
  "tsup": "^8.2.4",
57
57
  "typescript": "^5.5.4",
58
- "vite": "^7.1.9",
58
+ "vite": "^7.3.1",
59
59
  "vitest": "^3.2.4"
60
60
  },
61
61
  "peerDependencies": {
62
- "@vitejs/plugin-react": "^4.6.0",
63
- "react": "^19.0.0",
64
- "react-dom": "^19.0.0",
62
+ "@vitejs/plugin-react": "^5.1.2",
63
+ "react": "^19.2.3",
64
+ "react-dom": "^19.2.3",
65
65
  "typescript": "^5.5.4",
66
- "vite": "^7.1.9"
66
+ "vite": "^7.3.1"
67
67
  },
68
68
  "peerDependenciesMeta": {
69
69
  "react": {