@tanstack/redact 0.0.1

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.
Files changed (233) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +4 -0
  3. package/dist/core/index.js.map +7 -0
  4. package/dist/core/internal.d.ts +76 -0
  5. package/dist/core/internal.js +59 -0
  6. package/dist/core/internal.js.map +7 -0
  7. package/dist/core/types.d.ts +21 -0
  8. package/dist/core/types.js +10 -0
  9. package/dist/core/types.js.map +7 -0
  10. package/dist/dom/_all.d.ts +17 -0
  11. package/dist/dom/_all.js +51 -0
  12. package/dist/dom/_all.js.map +7 -0
  13. package/dist/dom/client.d.ts +3 -0
  14. package/dist/dom/client.js +8 -0
  15. package/dist/dom/client.js.map +7 -0
  16. package/dist/dom/dispatcher.d.ts +20 -0
  17. package/dist/dom/dispatcher.js +267 -0
  18. package/dist/dom/dispatcher.js.map +7 -0
  19. package/dist/dom/dom.d.ts +10 -0
  20. package/dist/dom/dom.js +262 -0
  21. package/dist/dom/dom.js.map +7 -0
  22. package/dist/dom/event-replay.d.ts +13 -0
  23. package/dist/dom/event-replay.js +46 -0
  24. package/dist/dom/event-replay.js.map +7 -0
  25. package/dist/dom/features/class/full.d.ts +1 -0
  26. package/dist/dom/features/class/full.js +91 -0
  27. package/dist/dom/features/class/full.js.map +7 -0
  28. package/dist/dom/features/class/index.d.ts +1 -0
  29. package/dist/dom/features/class/index.js +3 -0
  30. package/dist/dom/features/class/index.js.map +7 -0
  31. package/dist/dom/features/class/stub.d.ts +1 -0
  32. package/dist/dom/features/class/stub.js +50 -0
  33. package/dist/dom/features/class/stub.js.map +7 -0
  34. package/dist/dom/features/context/full.d.ts +1 -0
  35. package/dist/dom/features/context/full.js +49 -0
  36. package/dist/dom/features/context/full.js.map +7 -0
  37. package/dist/dom/features/context/index.d.ts +1 -0
  38. package/dist/dom/features/context/index.js +3 -0
  39. package/dist/dom/features/context/index.js.map +7 -0
  40. package/dist/dom/features/context/stub.d.ts +1 -0
  41. package/dist/dom/features/context/stub.js +22 -0
  42. package/dist/dom/features/context/stub.js.map +7 -0
  43. package/dist/dom/features/forward-ref/full.d.ts +1 -0
  44. package/dist/dom/features/forward-ref/full.js +51 -0
  45. package/dist/dom/features/forward-ref/full.js.map +7 -0
  46. package/dist/dom/features/forward-ref/index.d.ts +1 -0
  47. package/dist/dom/features/forward-ref/index.js +3 -0
  48. package/dist/dom/features/forward-ref/index.js.map +7 -0
  49. package/dist/dom/features/forward-ref/stub.d.ts +1 -0
  50. package/dist/dom/features/forward-ref/stub.js +22 -0
  51. package/dist/dom/features/forward-ref/stub.js.map +7 -0
  52. package/dist/dom/features/hydration/full.d.ts +61 -0
  53. package/dist/dom/features/hydration/full.js +264 -0
  54. package/dist/dom/features/hydration/full.js.map +7 -0
  55. package/dist/dom/features/hydration/index.d.ts +1 -0
  56. package/dist/dom/features/hydration/index.js +3 -0
  57. package/dist/dom/features/hydration/index.js.map +7 -0
  58. package/dist/dom/features/hydration/stub.d.ts +28 -0
  59. package/dist/dom/features/hydration/stub.js +66 -0
  60. package/dist/dom/features/hydration/stub.js.map +7 -0
  61. package/dist/dom/features/index.d.ts +7 -0
  62. package/dist/dom/features/index.js +9 -0
  63. package/dist/dom/features/index.js.map +7 -0
  64. package/dist/dom/features/lazy/full.d.ts +1 -0
  65. package/dist/dom/features/lazy/full.js +78 -0
  66. package/dist/dom/features/lazy/full.js.map +7 -0
  67. package/dist/dom/features/lazy/index.d.ts +1 -0
  68. package/dist/dom/features/lazy/index.js +3 -0
  69. package/dist/dom/features/lazy/index.js.map +7 -0
  70. package/dist/dom/features/lazy/stub.d.ts +1 -0
  71. package/dist/dom/features/lazy/stub.js +36 -0
  72. package/dist/dom/features/lazy/stub.js.map +7 -0
  73. package/dist/dom/features/memo/full.d.ts +1 -0
  74. package/dist/dom/features/memo/full.js +59 -0
  75. package/dist/dom/features/memo/full.js.map +7 -0
  76. package/dist/dom/features/memo/index.d.ts +1 -0
  77. package/dist/dom/features/memo/index.js +3 -0
  78. package/dist/dom/features/memo/index.js.map +7 -0
  79. package/dist/dom/features/memo/stub.d.ts +1 -0
  80. package/dist/dom/features/memo/stub.js +36 -0
  81. package/dist/dom/features/memo/stub.js.map +7 -0
  82. package/dist/dom/features/portal/full.d.ts +1 -0
  83. package/dist/dom/features/portal/full.js +19 -0
  84. package/dist/dom/features/portal/full.js.map +7 -0
  85. package/dist/dom/features/portal/index.d.ts +1 -0
  86. package/dist/dom/features/portal/index.js +3 -0
  87. package/dist/dom/features/portal/index.js.map +7 -0
  88. package/dist/dom/features/portal/stub.d.ts +1 -0
  89. package/dist/dom/features/portal/stub.js +7 -0
  90. package/dist/dom/features/portal/stub.js.map +7 -0
  91. package/dist/dom/features/suspense/full.d.ts +1 -0
  92. package/dist/dom/features/suspense/full.js +146 -0
  93. package/dist/dom/features/suspense/full.js.map +7 -0
  94. package/dist/dom/features/suspense/index.d.ts +1 -0
  95. package/dist/dom/features/suspense/index.js +3 -0
  96. package/dist/dom/features/suspense/index.js.map +7 -0
  97. package/dist/dom/features/suspense/stub.d.ts +1 -0
  98. package/dist/dom/features/suspense/stub.js +6 -0
  99. package/dist/dom/features/suspense/stub.js.map +7 -0
  100. package/dist/dom/index.d.ts +25 -0
  101. package/dist/dom/index.js +45 -0
  102. package/dist/dom/index.js.map +7 -0
  103. package/dist/dom/portal.d.ts +2 -0
  104. package/dist/dom/portal.js +15 -0
  105. package/dist/dom/portal.js.map +7 -0
  106. package/dist/dom/reconcile.d.ts +40 -0
  107. package/dist/dom/reconcile.js +795 -0
  108. package/dist/dom/reconcile.js.map +7 -0
  109. package/dist/dom/root.d.ts +15 -0
  110. package/dist/dom/root.js +85 -0
  111. package/dist/dom/root.js.map +7 -0
  112. package/dist/dom/test-utils.d.ts +1 -0
  113. package/dist/dom/test-utils.js +10 -0
  114. package/dist/dom/test-utils.js.map +7 -0
  115. package/dist/react/children.d.ts +8 -0
  116. package/dist/react/children.js +75 -0
  117. package/dist/react/children.js.map +7 -0
  118. package/dist/react/class.d.ts +31 -0
  119. package/dist/react/class.js +40 -0
  120. package/dist/react/class.js.map +7 -0
  121. package/dist/react/context.d.ts +27 -0
  122. package/dist/react/context.js +31 -0
  123. package/dist/react/context.js.map +7 -0
  124. package/dist/react/element.d.ts +10 -0
  125. package/dist/react/element.js +64 -0
  126. package/dist/react/element.js.map +7 -0
  127. package/dist/react/hooks.d.ts +37 -0
  128. package/dist/react/hooks.js +146 -0
  129. package/dist/react/hooks.js.map +7 -0
  130. package/dist/react/index.d.ts +76 -0
  131. package/dist/react/index.js +187 -0
  132. package/dist/react/index.js.map +7 -0
  133. package/dist/react/jsx-runtime.d.ts +5 -0
  134. package/dist/react/jsx-runtime.js +21 -0
  135. package/dist/react/jsx-runtime.js.map +7 -0
  136. package/dist/react/memo.d.ts +29 -0
  137. package/dist/react/memo.js +47 -0
  138. package/dist/react/memo.js.map +7 -0
  139. package/dist/react/portal.d.ts +1 -0
  140. package/dist/react/portal.js +6 -0
  141. package/dist/react/portal.js.map +7 -0
  142. package/dist/react/shared-internals.d.ts +33 -0
  143. package/dist/react/shared-internals.js +29 -0
  144. package/dist/react/shared-internals.js.map +7 -0
  145. package/dist/react/suspense.d.ts +15 -0
  146. package/dist/react/suspense.js +16 -0
  147. package/dist/react/suspense.js.map +7 -0
  148. package/dist/scheduler/index.d.ts +44 -0
  149. package/dist/scheduler/index.js +109 -0
  150. package/dist/scheduler/index.js.map +7 -0
  151. package/dist/server/bootstrap-script.d.ts +22 -0
  152. package/dist/server/bootstrap-script.js +16 -0
  153. package/dist/server/bootstrap-script.js.map +7 -0
  154. package/dist/server/dispatcher.d.ts +37 -0
  155. package/dist/server/dispatcher.js +140 -0
  156. package/dist/server/dispatcher.js.map +7 -0
  157. package/dist/server/escape.d.ts +7 -0
  158. package/dist/server/escape.js +159 -0
  159. package/dist/server/escape.js.map +7 -0
  160. package/dist/server/index.d.ts +16 -0
  161. package/dist/server/index.js +26 -0
  162. package/dist/server/index.js.map +7 -0
  163. package/dist/server/renderToString.d.ts +7 -0
  164. package/dist/server/renderToString.js +29 -0
  165. package/dist/server/renderToString.js.map +7 -0
  166. package/dist/server/stream.d.ts +40 -0
  167. package/dist/server/stream.js +200 -0
  168. package/dist/server/stream.js.map +7 -0
  169. package/dist/server/walk.d.ts +33 -0
  170. package/dist/server/walk.js +298 -0
  171. package/dist/server/walk.js.map +7 -0
  172. package/dist/vite/index.d.ts +96 -0
  173. package/dist/vite/index.js +217 -0
  174. package/dist/vite/index.js.map +7 -0
  175. package/package.json +83 -0
  176. package/src/core/index.ts +2 -0
  177. package/src/core/internal.ts +107 -0
  178. package/src/core/types.ts +36 -0
  179. package/src/dom/_all.ts +54 -0
  180. package/src/dom/client.ts +4 -0
  181. package/src/dom/dispatcher.ts +318 -0
  182. package/src/dom/dom.ts +316 -0
  183. package/src/dom/event-replay.ts +55 -0
  184. package/src/dom/features/class/full.ts +104 -0
  185. package/src/dom/features/class/index.ts +1 -0
  186. package/src/dom/features/class/stub.ts +65 -0
  187. package/src/dom/features/context/full.ts +57 -0
  188. package/src/dom/features/context/index.ts +1 -0
  189. package/src/dom/features/context/stub.ts +32 -0
  190. package/src/dom/features/forward-ref/full.ts +54 -0
  191. package/src/dom/features/forward-ref/index.ts +1 -0
  192. package/src/dom/features/forward-ref/stub.ts +28 -0
  193. package/src/dom/features/hydration/full.ts +345 -0
  194. package/src/dom/features/hydration/index.ts +1 -0
  195. package/src/dom/features/hydration/stub.ts +72 -0
  196. package/src/dom/features/index.ts +11 -0
  197. package/src/dom/features/lazy/full.ts +98 -0
  198. package/src/dom/features/lazy/index.ts +1 -0
  199. package/src/dom/features/lazy/stub.ts +45 -0
  200. package/src/dom/features/memo/full.ts +74 -0
  201. package/src/dom/features/memo/index.ts +1 -0
  202. package/src/dom/features/memo/stub.ts +42 -0
  203. package/src/dom/features/portal/full.ts +22 -0
  204. package/src/dom/features/portal/index.ts +1 -0
  205. package/src/dom/features/portal/stub.ts +11 -0
  206. package/src/dom/features/suspense/full.ts +191 -0
  207. package/src/dom/features/suspense/index.ts +1 -0
  208. package/src/dom/features/suspense/stub.ts +12 -0
  209. package/src/dom/index.ts +33 -0
  210. package/src/dom/portal.ts +16 -0
  211. package/src/dom/reconcile.ts +1169 -0
  212. package/src/dom/root.ts +107 -0
  213. package/src/dom/test-utils.ts +6 -0
  214. package/src/react/children.ts +85 -0
  215. package/src/react/class.ts +56 -0
  216. package/src/react/context.ts +50 -0
  217. package/src/react/element.ts +80 -0
  218. package/src/react/hooks.ts +190 -0
  219. package/src/react/index.ts +132 -0
  220. package/src/react/jsx-runtime.ts +16 -0
  221. package/src/react/memo.ts +45 -0
  222. package/src/react/portal.ts +1 -0
  223. package/src/react/shared-internals.ts +79 -0
  224. package/src/react/suspense.ts +18 -0
  225. package/src/scheduler/index.ts +124 -0
  226. package/src/server/bootstrap-script.ts +52 -0
  227. package/src/server/dispatcher.ts +158 -0
  228. package/src/server/escape.ts +187 -0
  229. package/src/server/index.ts +26 -0
  230. package/src/server/renderToString.ts +33 -0
  231. package/src/server/stream.ts +302 -0
  232. package/src/server/walk.ts +448 -0
  233. package/src/vite/index.ts +401 -0
@@ -0,0 +1,16 @@
1
+ import { REACT_ELEMENT_TYPE, type ReactElement } from '../core'
2
+
3
+ export { Fragment } from './element'
4
+
5
+ export function jsx(type: any, props: any, key?: any): ReactElement {
6
+ return {
7
+ $$typeof: REACT_ELEMENT_TYPE,
8
+ type,
9
+ key: key == null ? null : '' + key,
10
+ ref: props?.ref ?? null,
11
+ props,
12
+ }
13
+ }
14
+
15
+ export const jsxs = jsx
16
+ export const jsxDEV = jsx
@@ -0,0 +1,45 @@
1
+ export const REACT_MEMO_TYPE = Symbol.for('react.memo')
2
+ export const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref')
3
+ export const REACT_LAZY_TYPE = Symbol.for('react.lazy')
4
+
5
+ export function memo<P>(
6
+ type: (props: P) => any,
7
+ areEqual?: (prev: Readonly<P>, next: Readonly<P>) => boolean,
8
+ ) {
9
+ return { $$typeof: REACT_MEMO_TYPE, type, compare: areEqual ?? null }
10
+ }
11
+
12
+ export function forwardRef<R, P = {}>(
13
+ render: (props: P, ref: { current: R | null } | ((r: R | null) => void) | null) => any,
14
+ ) {
15
+ return { $$typeof: REACT_FORWARD_REF_TYPE, render }
16
+ }
17
+
18
+ export function lazy<T extends { default: any }>(ctor: () => Promise<T>) {
19
+ const payload = {
20
+ status: -1 as -1 | 0 | 1 | 2,
21
+ result: undefined as any,
22
+ }
23
+ return {
24
+ $$typeof: REACT_LAZY_TYPE,
25
+ _payload: payload,
26
+ _init: (p: typeof payload): any => {
27
+ if (p.status === 1) return p.result
28
+ if (p.status === 2) throw p.result
29
+ if (p.status === 0) throw p.result // pending promise
30
+ const thenable = ctor().then(
31
+ (mod) => {
32
+ p.status = 1
33
+ p.result = mod.default
34
+ },
35
+ (err) => {
36
+ p.status = 2
37
+ p.result = err
38
+ },
39
+ )
40
+ p.status = 0
41
+ p.result = thenable
42
+ throw thenable
43
+ },
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ export const REACT_PORTAL_TYPE = Symbol.for('react.portal')
@@ -0,0 +1,79 @@
1
+ import type { Fiber, FiberRoot, Hook } from '../core'
2
+
3
+ export interface Dispatcher {
4
+ useState<S>(initial: S | (() => S)): [S, (s: S | ((p: S) => S)) => void]
5
+ useReducer<S, A>(
6
+ reducer: (s: S, a: A) => S,
7
+ initial: S | any,
8
+ init?: (a: any) => S,
9
+ ): [S, (a: A) => void]
10
+ useEffect(create: () => any, deps?: ReadonlyArray<unknown>): void
11
+ useLayoutEffect(create: () => any, deps?: ReadonlyArray<unknown>): void
12
+ useInsertionEffect(create: () => any, deps?: ReadonlyArray<unknown>): void
13
+ useRef<T>(initial: T): { current: T }
14
+ useMemo<T>(factory: () => T, deps?: ReadonlyArray<unknown>): T
15
+ useCallback<T extends Function>(fn: T, deps?: ReadonlyArray<unknown>): T
16
+ useContext<T>(ctx: any): T
17
+ useImperativeHandle<T>(ref: any, factory: () => T, deps?: ReadonlyArray<unknown>): void
18
+ useDebugValue<T>(value: T, formatter?: (v: T) => any): void
19
+ useId(): string
20
+ useTransition(): [boolean, (fn: () => void) => void]
21
+ useDeferredValue<T>(v: T): T
22
+ useSyncExternalStore<T>(
23
+ subscribe: (cb: () => void) => () => void,
24
+ getSnapshot: () => T,
25
+ getServerSnapshot?: () => T,
26
+ ): T
27
+ use<T>(promiseOrContext: any): T
28
+ }
29
+
30
+ interface SharedInternals {
31
+ H: Dispatcher | null
32
+ T: any
33
+ S: ((fn: () => void) => void) | null
34
+ currentFiber: Fiber | null
35
+ currentRoot: FiberRoot | null
36
+ currentHook: Hook | null
37
+ hookIndex: number
38
+ }
39
+
40
+ // Stash the singleton on `globalThis` under a registered symbol. Module-scoped
41
+ // state goes wrong fast in environments that end up with multiple copies of
42
+ // `@tanstack/redact` in flight — most notably Cloudflare's `vite-plugin` dev
43
+ // mode, where the worker entry inlines `@tanstack/redact` once via `noExternal`
44
+ // while user code reaches a separate pre-bundled `deps_ssr/redact.js` copy.
45
+ // Each copy would otherwise have its own `ReactSharedInternals.H`, so the SSR
46
+ // dispatcher installed by one would be invisible to hooks called through the
47
+ // other and `useContext` would explode with "Hooks can only be called inside a
48
+ // function component". `Symbol.for` survives module re-evaluation and isolate
49
+ // boundaries, giving every copy the same backing object.
50
+ const KEY = Symbol.for('@tanstack/redact.ReactSharedInternals')
51
+ const g = globalThis as unknown as { [k: symbol]: SharedInternals | undefined }
52
+
53
+ export const ReactSharedInternals: SharedInternals =
54
+ g[KEY] ??
55
+ (g[KEY] = {
56
+ H: null,
57
+ T: null,
58
+ S: null,
59
+ currentFiber: null,
60
+ currentRoot: null,
61
+ currentHook: null,
62
+ hookIndex: 0,
63
+ })
64
+
65
+ export function getDispatcher(): Dispatcher {
66
+ const d = ReactSharedInternals.H
67
+ if (!d) {
68
+ if (process.env.NODE_ENV !== 'production') {
69
+ throw new Error(
70
+ 'Hooks can only be called inside a function component. ' +
71
+ 'If this fires during SSR/RSC, the most common cause is a component that uses client-only hooks ' +
72
+ '(useState, useContext, useRouter, etc.) being rendered in the RSC server environment without a ' +
73
+ '"use client" directive at the top of its file.',
74
+ )
75
+ }
76
+ throw new Error('Hooks can only be called inside a function component.')
77
+ }
78
+ return d
79
+ }
@@ -0,0 +1,18 @@
1
+ export const REACT_SUSPENSE_TYPE = Symbol.for('react.suspense')
2
+ export const REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode')
3
+ export const REACT_PROFILER_TYPE = Symbol.for('react.profiler')
4
+
5
+ export const Suspense = REACT_SUSPENSE_TYPE as any as (props: {
6
+ children?: any
7
+ fallback?: any
8
+ }) => any
9
+
10
+ export const StrictMode = REACT_STRICT_MODE_TYPE as any as (props: {
11
+ children?: any
12
+ }) => any
13
+
14
+ export const Profiler = REACT_PROFILER_TYPE as any as (props: {
15
+ id: string
16
+ onRender?: any
17
+ children?: any
18
+ }) => any
@@ -0,0 +1,124 @@
1
+ // Minimal `scheduler` package surface — enough for React-ecosystem libraries
2
+ // (react-three/fiber, react-query's older scheduler calls, some devtools) to
3
+ // resolve the import without crashing. We don't implement priority lanes or
4
+ // interruptible work; everything runs on microtask or the next task.
5
+
6
+ const PRIORITY_IMMEDIATE = 1
7
+ const PRIORITY_USER_BLOCKING = 2
8
+ const PRIORITY_NORMAL = 3
9
+ const PRIORITY_LOW = 4
10
+ const PRIORITY_IDLE = 5
11
+
12
+ type Callback = () => unknown
13
+
14
+ interface Task {
15
+ id: number
16
+ callback: Callback | null
17
+ priority: number
18
+ cancelled: boolean
19
+ }
20
+
21
+ let nextId = 0
22
+
23
+ export function unstable_scheduleCallback(priority: number, cb: Callback): Task {
24
+ const task: Task = {
25
+ id: ++nextId,
26
+ callback: cb,
27
+ priority,
28
+ cancelled: false,
29
+ }
30
+ const run = () => {
31
+ if (task.cancelled || !task.callback) return
32
+ const fn = task.callback
33
+ task.callback = null
34
+ try {
35
+ fn()
36
+ } catch (e) {
37
+ // Re-throw on next task so the host sees it
38
+ setTimeout(() => {
39
+ throw e
40
+ }, 0)
41
+ }
42
+ }
43
+ // Immediate → microtask so ordering is predictable; everything else → next task.
44
+ if (priority <= PRIORITY_IMMEDIATE) {
45
+ queueMicrotask(run)
46
+ } else {
47
+ setTimeout(run, 0)
48
+ }
49
+ return task
50
+ }
51
+
52
+ export function unstable_cancelCallback(task: Task): void {
53
+ task.cancelled = true
54
+ task.callback = null
55
+ }
56
+
57
+ export function unstable_shouldYield(): boolean {
58
+ // We never yield — work runs to completion on whichever task schedules it.
59
+ return false
60
+ }
61
+
62
+ export function unstable_requestPaint(): void {
63
+ // no-op
64
+ }
65
+
66
+ export function unstable_now(): number {
67
+ return typeof performance !== 'undefined' ? performance.now() : Date.now()
68
+ }
69
+
70
+ export function unstable_getCurrentPriorityLevel(): number {
71
+ return PRIORITY_NORMAL
72
+ }
73
+
74
+ export function unstable_runWithPriority<T>(_priority: number, fn: () => T): T {
75
+ return fn()
76
+ }
77
+
78
+ export function unstable_next<T>(fn: () => T): T {
79
+ return fn()
80
+ }
81
+
82
+ export function unstable_wrapCallback<T extends (...args: any[]) => any>(fn: T): T {
83
+ return fn
84
+ }
85
+
86
+ export function unstable_continueExecution(): void {
87
+ // no-op
88
+ }
89
+
90
+ export function unstable_pauseExecution(): void {
91
+ // no-op
92
+ }
93
+
94
+ export function unstable_getFirstCallbackNode(): Task | null {
95
+ return null
96
+ }
97
+
98
+ export const unstable_IdlePriority = PRIORITY_IDLE
99
+ export const unstable_ImmediatePriority = PRIORITY_IMMEDIATE
100
+ export const unstable_LowPriority = PRIORITY_LOW
101
+ export const unstable_NormalPriority = PRIORITY_NORMAL
102
+ export const unstable_UserBlockingPriority = PRIORITY_USER_BLOCKING
103
+
104
+ // Some libraries (e.g. @react-three/fiber) import `scheduler` with a default
105
+ // binding expecting the namespace object. Provide one.
106
+ export default {
107
+ unstable_scheduleCallback,
108
+ unstable_cancelCallback,
109
+ unstable_shouldYield,
110
+ unstable_requestPaint,
111
+ unstable_now,
112
+ unstable_getCurrentPriorityLevel,
113
+ unstable_runWithPriority,
114
+ unstable_next,
115
+ unstable_wrapCallback,
116
+ unstable_continueExecution,
117
+ unstable_pauseExecution,
118
+ unstable_getFirstCallbackNode,
119
+ unstable_IdlePriority,
120
+ unstable_ImmediatePriority,
121
+ unstable_LowPriority,
122
+ unstable_NormalPriority,
123
+ unstable_UserBlockingPriority,
124
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Inline client runtime injected into the streamed HTML. Two jobs:
3
+ *
4
+ * 1. Reveal suspense boundaries as their resolved chunks arrive ($RC).
5
+ * 2. Capture interaction events from the moment the shell is visible so the
6
+ * main bundle can replay them against un-hydrated subtrees ($RE_q buffer).
7
+ *
8
+ * Wire format:
9
+ * Fallback: <!--$?ID--><div hidden id="B:ID">fallback</div><!--/$-->
10
+ * Resolved: emits <div hidden id="S:ID">real</div><script>$RC(ID)</script>
11
+ * which splices real into place and rewrites the comment to <!--$ID-->.
12
+ *
13
+ * Client hydration calls $RH(ID, cb) to register a callback invoked once the
14
+ * boundary has been revealed (or immediately, if it was already revealed).
15
+ *
16
+ * Early-event buffering: before the main bundle is parsed, we attach capture
17
+ * listeners for a small set of interactive events and push them into a buffer.
18
+ * The bundle drains and replays them via the replay code in @tanstack/redact/dom.
19
+ */
20
+ export const BOUNDARY_REVEAL_RUNTIME =
21
+ `(function(){` +
22
+ `var c={};` +
23
+ `window.$RH=function(i,f){` +
24
+ `if(!document.getElementById("B:"+i))f();` +
25
+ `else c[i]=f;` +
26
+ `};` +
27
+ `window.$RC=function(i){` +
28
+ `var s=document.getElementById("S:"+i),b=document.getElementById("B:"+i);` +
29
+ `if(!s||!b)return;` +
30
+ `var p=b.parentNode,m=b.previousSibling;` +
31
+ `while(s.firstChild)p.insertBefore(s.firstChild,b);` +
32
+ `s.parentNode.removeChild(s);` +
33
+ `p.removeChild(b);` +
34
+ `if(m&&m.nodeType===8)m.data="$"+i;` +
35
+ `if(c[i]){var f=c[i];delete c[i];f()}` +
36
+ `};` +
37
+ `var q=[];window.$RE_q=q;` +
38
+ `var evs=["click","submit","input","change","keydown"];` +
39
+ `function h(e){q.push([e.type,e.target,e.timeStamp])}` +
40
+ `for(var j=0;j<evs.length;j++)document.addEventListener(evs[j],h,true);` +
41
+ `window.$RE_stop=function(){for(var j=0;j<evs.length;j++)document.removeEventListener(evs[j],h,true)};` +
42
+ `})();`
43
+
44
+ export function injectBootstrapScript(nonce?: string): string {
45
+ const n = nonce ? ` nonce="${nonce}"` : ''
46
+ return `<script${n}>${BOUNDARY_REVEAL_RUNTIME}</script>`
47
+ }
48
+
49
+ export function revealScript(id: number, nonce?: string): string {
50
+ const n = nonce ? ` nonce="${nonce}"` : ''
51
+ return `<script${n}>$RC(${id})</script>`
52
+ }
@@ -0,0 +1,158 @@
1
+ import { ReactSharedInternals, REACT_CONTEXT_TYPE } from '../react'
2
+
3
+ interface SSRFrame {
4
+ idCounter: number
5
+ identifierPrefix: string
6
+ contextStack: Array<{ context: any; prev: any }>
7
+ }
8
+
9
+ let frame: SSRFrame | null = null
10
+
11
+ export function beginSSR(identifierPrefix = ':R'): void {
12
+ frame = { idCounter: 0, identifierPrefix, contextStack: [] }
13
+ }
14
+
15
+ export function endSSR(): void {
16
+ // Restore any remaining pushed contexts (defensive)
17
+ if (frame) {
18
+ for (let i = frame.contextStack.length - 1; i >= 0; i--) {
19
+ const { context, prev } = frame.contextStack[i]!
20
+ context._currentValue = prev
21
+ }
22
+ }
23
+ frame = null
24
+ }
25
+
26
+ export function pushContext(context: any, value: any): void {
27
+ if (!frame) throw new Error('pushContext called outside SSR')
28
+ frame.contextStack.push({ context, prev: context._currentValue })
29
+ context._currentValue = value
30
+ }
31
+
32
+ export function popContext(context: any): void {
33
+ if (!frame) return
34
+ const top = frame.contextStack.pop()
35
+ if (top && top.context === context) context._currentValue = top.prev
36
+ }
37
+
38
+ export type ContextSnapshot = Array<{ context: any; value: any }>
39
+
40
+ export function snapshotContexts(): ContextSnapshot {
41
+ if (!frame) return []
42
+ const out: ContextSnapshot = []
43
+ for (const entry of frame.contextStack) {
44
+ out.push({ context: entry.context, value: entry.context._currentValue })
45
+ }
46
+ return out
47
+ }
48
+
49
+ /**
50
+ * Push snapshot values and return a function that pops them.
51
+ * Called when we re-render a suspended boundary so it sees the same provider
52
+ * values that were active at suspension time.
53
+ */
54
+ export function applyContextSnapshot(snapshot: ContextSnapshot): () => void {
55
+ for (const { context, value } of snapshot) pushContext(context, value)
56
+ return () => {
57
+ for (let i = snapshot.length - 1; i >= 0; i--) popContext(snapshot[i]!.context)
58
+ }
59
+ }
60
+
61
+ export const ssrDispatcher = {
62
+ useState<S>(initial: S | (() => S)) {
63
+ const v = typeof initial === 'function' ? (initial as () => S)() : initial
64
+ return [v, (() => {}) as any] as [S, any]
65
+ },
66
+ useReducer<S, A>(_reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S) {
67
+ const v = init ? init(initialArg) : initialArg
68
+ return [v, (() => {}) as any]
69
+ },
70
+ useEffect() {
71
+ // noop on server
72
+ },
73
+ useLayoutEffect() {
74
+ // noop on server
75
+ },
76
+ useInsertionEffect() {
77
+ // noop on server
78
+ },
79
+ useRef<T>(initial: T) {
80
+ return { current: initial }
81
+ },
82
+ useMemo<T>(factory: () => T) {
83
+ return factory()
84
+ },
85
+ useCallback<T extends Function>(fn: T) {
86
+ return fn
87
+ },
88
+ useContext<T>(ctx: any): T {
89
+ return ctx._currentValue
90
+ },
91
+ useImperativeHandle() {
92
+ // noop on server
93
+ },
94
+ useDebugValue() {
95
+ // noop
96
+ },
97
+ useId(): string {
98
+ if (!frame) return ':r0:'
99
+ return `${frame.identifierPrefix}${(frame.idCounter++).toString(36)}`
100
+ },
101
+ useTransition(): [boolean, (fn: () => void) => void] {
102
+ return [false, (fn) => fn()]
103
+ },
104
+ useDeferredValue<T>(v: T): T {
105
+ return v
106
+ },
107
+ useSyncExternalStore<T>(
108
+ _subscribe: (cb: () => void) => () => void,
109
+ getSnapshot: () => T,
110
+ getServerSnapshot?: () => T,
111
+ ): T {
112
+ return getServerSnapshot ? getServerSnapshot() : getSnapshot()
113
+ },
114
+ use<T>(resource: any): T {
115
+ if (resource == null) throw new Error('use() received null or undefined')
116
+ if (resource.$$typeof === REACT_CONTEXT_TYPE) {
117
+ return resource._currentValue
118
+ }
119
+ if (typeof resource.then === 'function') {
120
+ const thenable = resource
121
+ switch (thenable.status) {
122
+ case 'fulfilled':
123
+ return thenable.value
124
+ case 'rejected':
125
+ throw thenable.reason
126
+ default: {
127
+ if (thenable.status === undefined) {
128
+ thenable.status = 'pending'
129
+ thenable.then(
130
+ (v: any) => {
131
+ if (thenable.status === 'pending') {
132
+ thenable.status = 'fulfilled'
133
+ thenable.value = v
134
+ }
135
+ },
136
+ (e: any) => {
137
+ if (thenable.status === 'pending') {
138
+ thenable.status = 'rejected'
139
+ thenable.reason = e
140
+ }
141
+ },
142
+ )
143
+ }
144
+ throw thenable
145
+ }
146
+ }
147
+ }
148
+ throw new Error('use() expected a Promise or Context')
149
+ },
150
+ }
151
+
152
+ export function installSSRDispatcher(): void {
153
+ ReactSharedInternals.H = ssrDispatcher as any
154
+ }
155
+
156
+ export function uninstallSSRDispatcher(): void {
157
+ ReactSharedInternals.H = null
158
+ }
@@ -0,0 +1,187 @@
1
+ const ATTR_MAP: Record<string, string> = {
2
+ '&': '&amp;',
3
+ '"': '&quot;',
4
+ '<': '&lt;',
5
+ '>': '&gt;',
6
+ }
7
+ const TEXT_MAP: Record<string, string> = {
8
+ '&': '&amp;',
9
+ '<': '&lt;',
10
+ '>': '&gt;',
11
+ }
12
+
13
+ export function escapeAttr(value: string): string {
14
+ return value.replace(/[&"<>]/g, (c) => ATTR_MAP[c]!)
15
+ }
16
+
17
+ export function escapeText(value: string): string {
18
+ return value.replace(/[&<>]/g, (c) => TEXT_MAP[c]!)
19
+ }
20
+
21
+ // Raw-text element body escaping: prevent any closing tag for the raw-text
22
+ // elements (<script>, <style>) from terminating the element early, plus
23
+ // `<!--` (which would start an HTML comment that survives even inside
24
+ // raw-text bodies and can be exploited to alter following script content).
25
+ // React's serializer follows the same approach.
26
+ export function escapeScript(value: string): string {
27
+ return value
28
+ .replace(/<\/(script|style)/gi, '<\\/$1')
29
+ .replace(/<!--/g, '<\\!--')
30
+ }
31
+
32
+ export const VOID_ELEMENTS = new Set([
33
+ 'area',
34
+ 'base',
35
+ 'br',
36
+ 'col',
37
+ 'embed',
38
+ 'hr',
39
+ 'img',
40
+ 'input',
41
+ 'link',
42
+ 'meta',
43
+ 'param',
44
+ 'source',
45
+ 'track',
46
+ 'wbr',
47
+ ])
48
+
49
+ export const RAW_TEXT_ELEMENTS = new Set(['script', 'style'])
50
+
51
+ // Map JSX prop names to HTML attribute names where they differ
52
+ export const ATTR_ALIASES: Record<string, string> = {
53
+ className: 'class',
54
+ htmlFor: 'for',
55
+ httpEquiv: 'http-equiv',
56
+ acceptCharset: 'accept-charset',
57
+ crossOrigin: 'crossorigin',
58
+ viewBox: 'viewBox', // SVG keeps camelCase
59
+ noModule: 'nomodule',
60
+ }
61
+
62
+ const BOOLEAN_ATTRS = new Set([
63
+ 'allowfullscreen',
64
+ 'async',
65
+ 'autofocus',
66
+ 'autoplay',
67
+ 'checked',
68
+ 'controls',
69
+ 'default',
70
+ 'defer',
71
+ 'disabled',
72
+ 'formnovalidate',
73
+ 'hidden',
74
+ 'inert',
75
+ 'ismap',
76
+ 'itemscope',
77
+ 'loop',
78
+ 'multiple',
79
+ 'muted',
80
+ 'nomodule',
81
+ 'novalidate',
82
+ 'open',
83
+ 'playsinline',
84
+ 'readonly',
85
+ 'required',
86
+ 'reversed',
87
+ 'selected',
88
+ ])
89
+
90
+ export function attrToHtml(name: string, value: unknown): string {
91
+ if (
92
+ name === 'children' ||
93
+ name === 'key' ||
94
+ name === 'ref' ||
95
+ name === 'dangerouslySetInnerHTML' ||
96
+ name === 'defaultValue' ||
97
+ name === 'defaultChecked' ||
98
+ name === 'suppressHydrationWarning' ||
99
+ name === 'suppressContentEditableWarning'
100
+ ) {
101
+ return ''
102
+ }
103
+ if (name[0] === 'o' && name[1] === 'n' && typeof value === 'function') return ''
104
+ if (value == null) return ''
105
+
106
+ const htmlName = ATTR_ALIASES[name] ?? name.toLowerCase()
107
+
108
+ // aria-* and data-* stringify booleans to `"true"`/`"false"` rather than
109
+ // using boolean-attribute presence semantics — matches React and the ARIA
110
+ // spec. Must branch before the general `value === false` / BOOLEAN_ATTRS
111
+ // path, which would drop them.
112
+ if (name.startsWith('aria-') || name.startsWith('data-')) {
113
+ return ` ${htmlName}="${escapeAttr(String(value))}"`
114
+ }
115
+
116
+ if (value === false) return ''
117
+
118
+ if (value === true || BOOLEAN_ATTRS.has(htmlName)) {
119
+ return value ? ` ${htmlName}=""` : ''
120
+ }
121
+
122
+ if (name === 'style' && typeof value === 'object' && value !== null) {
123
+ return ` style="${escapeAttr(styleToString(value as Record<string, unknown>))}"`
124
+ }
125
+
126
+ return ` ${htmlName}="${escapeAttr(String(value))}"`
127
+ }
128
+
129
+ const UNITLESS_STYLE = new Set([
130
+ 'animationIterationCount',
131
+ 'borderImageOutset',
132
+ 'borderImageSlice',
133
+ 'borderImageWidth',
134
+ 'boxFlex',
135
+ 'boxFlexGroup',
136
+ 'boxOrdinalGroup',
137
+ 'columnCount',
138
+ 'columns',
139
+ 'flex',
140
+ 'flexGrow',
141
+ 'flexPositive',
142
+ 'flexShrink',
143
+ 'flexNegative',
144
+ 'flexOrder',
145
+ 'gridArea',
146
+ 'gridRow',
147
+ 'gridRowEnd',
148
+ 'gridRowSpan',
149
+ 'gridRowStart',
150
+ 'gridColumn',
151
+ 'gridColumnEnd',
152
+ 'gridColumnSpan',
153
+ 'gridColumnStart',
154
+ 'fontWeight',
155
+ 'lineClamp',
156
+ 'lineHeight',
157
+ 'opacity',
158
+ 'order',
159
+ 'orphans',
160
+ 'tabSize',
161
+ 'widows',
162
+ 'zIndex',
163
+ 'zoom',
164
+ 'fillOpacity',
165
+ 'floodOpacity',
166
+ 'stopOpacity',
167
+ 'strokeDasharray',
168
+ 'strokeDashoffset',
169
+ 'strokeMiterlimit',
170
+ 'strokeOpacity',
171
+ 'strokeWidth',
172
+ ])
173
+
174
+ function styleToString(style: Record<string, unknown>): string {
175
+ let out = ''
176
+ for (const key in style) {
177
+ const v = style[key]
178
+ if (v == null || v === false) continue
179
+ const kebab = key.startsWith('--')
180
+ ? key
181
+ : key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase())
182
+ const value =
183
+ typeof v === 'number' && !UNITLESS_STYLE.has(key) && v !== 0 ? v + 'px' : v
184
+ out += `${kebab}:${value};`
185
+ }
186
+ return out
187
+ }