@bleedingdev/tanstack-redact 0.2.2 → 0.3.2
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/bundler-core/resolution.d.ts +31 -0
- package/dist/bundler-core/resolution.js +80 -0
- package/dist/bundler-core/resolution.js.map +7 -0
- package/dist/bundler-core/selection.d.ts +89 -0
- package/dist/bundler-core/selection.js +103 -0
- package/dist/bundler-core/selection.js.map +7 -0
- package/dist/core/devtools.d.ts +1 -1
- package/dist/core/devtools.js +1 -0
- package/dist/core/devtools.js.map +2 -2
- package/dist/core/functions.js +1 -0
- package/dist/core/functions.js.map +2 -2
- package/dist/core/internal.d.ts +5 -4
- package/dist/core/internal.js +4 -3
- package/dist/core/internal.js.map +2 -2
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -0
- package/dist/core/types.js.map +1 -1
- package/dist/dom/devtools.d.ts +5 -5
- package/dist/dom/devtools.js +1 -0
- package/dist/dom/devtools.js.map +2 -2
- package/dist/dom/dispatcher.d.ts +1 -1
- package/dist/dom/dispatcher.js +1 -0
- package/dist/dom/dispatcher.js.map +3 -3
- package/dist/dom/document-metadata.d.ts +1 -1
- package/dist/dom/document-metadata.js +3 -1
- package/dist/dom/document-metadata.js.map +2 -2
- package/dist/dom/dom.js +1 -1
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/features/class/full.js +25 -32
- package/dist/dom/features/class/full.js.map +2 -2
- package/dist/dom/features/class/stub.js +1 -0
- package/dist/dom/features/class/stub.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +6 -6
- package/dist/dom/features/hydration/full.js +20 -29
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/stub.d.ts +7 -2
- package/dist/dom/features/hydration/stub.js +1 -0
- package/dist/dom/features/hydration/stub.js.map +2 -2
- package/dist/dom/features/lazy/full.js +1 -0
- package/dist/dom/features/lazy/full.js.map +2 -2
- package/dist/dom/features/suspense/full.d.ts +4 -1
- package/dist/dom/features/suspense/full.js +22 -161
- package/dist/dom/features/suspense/full.js.map +2 -2
- package/dist/dom/features/suspense-hydration/full.d.ts +8 -0
- package/dist/dom/features/suspense-hydration/full.js +147 -0
- package/dist/dom/features/suspense-hydration/full.js.map +7 -0
- package/dist/dom/features/suspense-hydration/index.d.ts +1 -0
- package/dist/dom/features/suspense-hydration/index.js +2 -0
- package/dist/dom/features/suspense-hydration/index.js.map +7 -0
- package/dist/dom/features/suspense-hydration/stub.d.ts +2 -0
- package/dist/dom/features/suspense-hydration/stub.js +9 -0
- package/dist/dom/features/suspense-hydration/stub.js.map +7 -0
- package/dist/dom/features/suspense-runtime/stub.js +1 -0
- package/dist/dom/features/suspense-runtime/stub.js.map +2 -2
- package/dist/dom/profiling.d.ts +36 -0
- package/dist/dom/profiling.js +9 -0
- package/dist/dom/profiling.js.map +7 -0
- package/dist/dom/react-ids.js +1 -0
- package/dist/dom/react-ids.js.map +2 -2
- package/dist/dom/reconcile.d.ts +4 -5
- package/dist/dom/reconcile.js +102 -144
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/resources.js +1 -0
- package/dist/dom/resources.js.map +2 -2
- package/dist/dom/root-internal.d.ts +1 -1
- package/dist/dom/root-internal.js +4 -3
- package/dist/dom/root-internal.js.map +2 -2
- package/dist/dom/root.d.ts +2 -2
- package/dist/dom/root.js +1 -0
- package/dist/dom/root.js.map +2 -2
- package/dist/dom/synthetic-event.js.map +2 -2
- package/dist/dom/transitions.d.ts +1 -1
- package/dist/dom/transitions.js +1 -0
- package/dist/dom/transitions.js.map +2 -2
- package/dist/react/action-scope.d.ts +1 -1
- package/dist/react/action-scope.js +1 -0
- package/dist/react/action-scope.js.map +2 -2
- package/dist/rspack/index.d.ts +2 -0
- package/dist/rspack/index.js +6 -0
- package/dist/rspack/index.js.map +7 -0
- package/dist/server/bootstrap-script.js +1 -0
- package/dist/server/bootstrap-script.js.map +2 -2
- package/dist/server/dispatcher.js +11 -20
- package/dist/server/dispatcher.js.map +2 -2
- package/dist/server/insertion-context.js +9 -16
- package/dist/server/insertion-context.js.map +7 -0
- package/dist/server/stream-ids.js +1 -0
- package/dist/server/stream-ids.js.map +7 -0
- package/dist/server/stream.d.ts +1 -2
- package/dist/server/stream.js +106 -122
- package/dist/server/stream.js.map +2 -2
- package/dist/server/walk.js +69 -72
- package/dist/server/walk.js.map +3 -3
- package/dist/vite/index.d.ts +5 -99
- package/dist/vite/index.js +56 -179
- package/dist/vite/index.js.map +2 -2
- package/dist/webpack/index.d.ts +46 -0
- package/dist/webpack/index.js +102 -0
- package/dist/webpack/index.js.map +7 -0
- package/dist/webpack/react18-loader.cjs +25 -0
- package/package.json +17 -3
- package/src/bundler-core/resolution.ts +131 -0
- package/src/bundler-core/selection.ts +192 -0
- package/src/core/internal.ts +2 -1
- package/src/core/types.ts +3 -2
- package/src/dom/dom.ts +1 -1
- package/src/dom/features/class/full.ts +26 -34
- package/src/dom/features/suspense/full.ts +7 -165
- package/src/dom/features/suspense-hydration/full.ts +166 -0
- package/src/dom/features/suspense-hydration/index.ts +1 -0
- package/src/dom/features/suspense-hydration/stub.ts +2 -0
- package/src/dom/profiling.ts +6 -0
- package/src/dom/reconcile.ts +16 -6
- package/src/rspack/index.ts +2 -0
- package/src/server/stream.ts +15 -14
- package/src/vite/index.ts +55 -317
- package/src/webpack/index.ts +108 -0
- package/src/webpack/react18-loader.cjs +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bleedingdev/tanstack-redact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "An alternative runtime for React apps, with a smaller footprint and synchronous rendering.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/react/index.js",
|
|
@@ -66,6 +66,18 @@
|
|
|
66
66
|
"./cloudflare": {
|
|
67
67
|
"types": "./dist/cloudflare/index.d.ts",
|
|
68
68
|
"default": "./dist/cloudflare/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./webpack": {
|
|
71
|
+
"types": "./dist/webpack/index.d.ts",
|
|
72
|
+
"default": "./dist/webpack/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./rspack": {
|
|
75
|
+
"types": "./dist/rspack/index.d.ts",
|
|
76
|
+
"default": "./dist/rspack/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./dom-profiling": {
|
|
79
|
+
"types": "./dist/dom/profiling.d.ts",
|
|
80
|
+
"default": "./dist/dom/profiling.js"
|
|
69
81
|
}
|
|
70
82
|
},
|
|
71
83
|
"files": [
|
|
@@ -85,13 +97,15 @@
|
|
|
85
97
|
"./dist/dom/_all.js"
|
|
86
98
|
],
|
|
87
99
|
"dependencies": {
|
|
100
|
+
"@jridgewell/remapping": "^2.3.5",
|
|
101
|
+
"acorn": "^8.19.0",
|
|
88
102
|
"magic-string": "^0.30.21"
|
|
89
103
|
},
|
|
90
104
|
"peerDependencies": {
|
|
105
|
+
"@cloudflare/vite-plugin": "1.65.0",
|
|
91
106
|
"next": "~15.5.0 || ~16.0.0 || ~16.1.0 || ~16.2.0 || ~16.3.0 || ~16.4.0",
|
|
92
|
-
"vite": ">=5",
|
|
93
107
|
"vinext": "~1.3.0",
|
|
94
|
-
"
|
|
108
|
+
"vite": ">=5"
|
|
95
109
|
},
|
|
96
110
|
"peerDependenciesMeta": {
|
|
97
111
|
"next": {
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { dirname, resolve as resolvePath } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import type { RedactPreset, RedactFeatures } from './selection'
|
|
5
|
+
|
|
6
|
+
export interface RedactOptions {
|
|
7
|
+
/** Skip aliasing specific specifiers, e.g. if a consumer wants real React somewhere. */
|
|
8
|
+
skip?: ReadonlyArray<string>
|
|
9
|
+
/**
|
|
10
|
+
* Override package resolution root. Defaults to the build config root. Useful
|
|
11
|
+
* for monorepos where the plugin lives in a different workspace than the
|
|
12
|
+
* consumer app.
|
|
13
|
+
*/
|
|
14
|
+
resolveFrom?: string
|
|
15
|
+
/**
|
|
16
|
+
* Explicit package roots, bypassing node_modules lookup. Keys are package
|
|
17
|
+
* names (e.g. `@tanstack/redact`), values are absolute paths to the package
|
|
18
|
+
* directory. Handy for cross-workspace testing / bring-your-own-build setups.
|
|
19
|
+
*/
|
|
20
|
+
packageRoots?: Record<string, string>
|
|
21
|
+
/**
|
|
22
|
+
* Starting point for feature selection. `'full'` (default) turns every
|
|
23
|
+
* stable feature on, with view transitions off. Disable individual features via
|
|
24
|
+
* `features`. `'nano'` turns everything off, opt in to what you need.
|
|
25
|
+
*/
|
|
26
|
+
preset?: RedactPreset
|
|
27
|
+
/**
|
|
28
|
+
* Per-feature overrides merged on top of the preset's defaults. Enables
|
|
29
|
+
* fine-grained "preset minus X" or "preset plus Y" configurations.
|
|
30
|
+
*/
|
|
31
|
+
features?: RedactFeatures
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function splitSpecifier(specifier: string): { pkg: string; sub: string } {
|
|
35
|
+
if (specifier.startsWith('@')) {
|
|
36
|
+
const slash1 = specifier.indexOf('/')
|
|
37
|
+
const slash2 = specifier.indexOf('/', slash1 + 1)
|
|
38
|
+
if (slash2 < 0) return { pkg: specifier, sub: '' }
|
|
39
|
+
return { pkg: specifier.slice(0, slash2), sub: specifier.slice(slash2 + 1) }
|
|
40
|
+
}
|
|
41
|
+
const slash = specifier.indexOf('/')
|
|
42
|
+
if (slash < 0) return { pkg: specifier, sub: '' }
|
|
43
|
+
return { pkg: specifier.slice(0, slash), sub: specifier.slice(slash + 1) }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function findPackageDir(pkg: string, fromDir: string): string | null {
|
|
47
|
+
let dir = resolvePath(fromDir)
|
|
48
|
+
while (true) {
|
|
49
|
+
const candidate = resolvePath(dir, 'node_modules', pkg)
|
|
50
|
+
if (existsSync(resolvePath(candidate, 'package.json'))) return candidate
|
|
51
|
+
const parent = dirname(dir)
|
|
52
|
+
if (parent === dir) return null
|
|
53
|
+
dir = parent
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function resolveExport(packageDir: string, sub: string): string | null {
|
|
58
|
+
const pkgJsonPath = resolvePath(packageDir, 'package.json')
|
|
59
|
+
let pkg: any
|
|
60
|
+
try {
|
|
61
|
+
pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))
|
|
62
|
+
} catch {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
const key = sub ? './' + sub : '.'
|
|
66
|
+
const exp = pkg.exports?.[key]
|
|
67
|
+
// Prefer published JavaScript over TypeScript sources. Dist preserves one
|
|
68
|
+
// file per module, so subpath imports share state and feature boundaries.
|
|
69
|
+
const pick = (v: any): string | null => {
|
|
70
|
+
if (typeof v === 'string') return v
|
|
71
|
+
if (v && typeof v === 'object') {
|
|
72
|
+
return pick(v.import) ?? pick(v.module) ?? pick(v.source) ?? pick(v.default)
|
|
73
|
+
}
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
const target = pick(exp)
|
|
77
|
+
if (target) return resolvePath(packageDir, target)
|
|
78
|
+
if (!sub) {
|
|
79
|
+
const main = pkg.module ?? pkg.main
|
|
80
|
+
if (typeof main === 'string') return resolvePath(packageDir, main)
|
|
81
|
+
}
|
|
82
|
+
return null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// When installed from npm, `@tanstack/redact` is declared as a `dependency`
|
|
86
|
+
// of consumer apps. Under pnpm's strict mode it ends up nested under the
|
|
87
|
+
// plugin's own `.pnpm/@tanstack+redact@.../node_modules/` rather than
|
|
88
|
+
// hoisted to the consumer's root, so a `findPackageDir` walk starting at
|
|
89
|
+
// the Vite project root won't always find it. Search from the plugin's own
|
|
90
|
+
// directory first (which walks into its nested node_modules), then fall
|
|
91
|
+
// back to the consumer root for hoisted installs.
|
|
92
|
+
const pluginDir = dirname(fileURLToPath(import.meta.url))
|
|
93
|
+
|
|
94
|
+
export function resolvePackageDir(
|
|
95
|
+
pkg: string,
|
|
96
|
+
fromDir: string,
|
|
97
|
+
packageRoots: Record<string, string>,
|
|
98
|
+
preferFrom = false,
|
|
99
|
+
): string | null {
|
|
100
|
+
return packageRoots[pkg] ?? (preferFrom
|
|
101
|
+
? findPackageDir(pkg, fromDir) ?? findPackageDir(pkg, pluginDir)
|
|
102
|
+
: findPackageDir(pkg, pluginDir) ?? findPackageDir(pkg, fromDir))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function resolveSpecifier(
|
|
106
|
+
specifier: string,
|
|
107
|
+
fromDir: string,
|
|
108
|
+
packageRoots: Record<string, string>,
|
|
109
|
+
preferFrom = false,
|
|
110
|
+
): string | null {
|
|
111
|
+
const { pkg, sub } = splitSpecifier(specifier)
|
|
112
|
+
const packageDir = resolvePackageDir(pkg, fromDir, packageRoots, preferFrom)
|
|
113
|
+
if (!packageDir) return null
|
|
114
|
+
const target = resolveExport(packageDir, sub)
|
|
115
|
+
if (!target) return null
|
|
116
|
+
// Canonicalize through pnpm symlinks. Under strict pnpm, the package may
|
|
117
|
+
// live nested under `.pnpm/@tanstack+redact@.../node_modules/*`, but each
|
|
118
|
+
// of those is itself a symlink to the flat `.pnpm/@tanstack+redact@.../`
|
|
119
|
+
// entry. Vite's `fetchModule` (used by TanStack Start's server-fn
|
|
120
|
+
// compiler) follows the realpath, so the id seen by the capture-transform
|
|
121
|
+
// differs from the nested id we'd return. That leaves the compiler's
|
|
122
|
+
// moduleCache keyed on the realpath while `getModuleInfo` looks up the
|
|
123
|
+
// nested path → miss → "could not load module info". Returning the
|
|
124
|
+
// canonical realpath here keeps the two sides in agreement.
|
|
125
|
+
try {
|
|
126
|
+
return realpathSync(target)
|
|
127
|
+
} catch {
|
|
128
|
+
return target
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export type RedactPreset = 'nano' | 'full'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Opt-in feature set. Each flag toggles whether the feature's real
|
|
5
|
+
* implementation ships (`true`) or is swapped with a stub module that
|
|
6
|
+
* degrades gracefully (`false`). Missing keys fall back to the preset's
|
|
7
|
+
* default. Adding a feature to this interface propagates to consumer
|
|
8
|
+
* configs as autocompleted options.
|
|
9
|
+
*/
|
|
10
|
+
export interface RedactFeatures {
|
|
11
|
+
/** Activity visibility, retained state and disconnected effects. */
|
|
12
|
+
activity?: boolean
|
|
13
|
+
/** DOM instances, events, focus, layout and observers for Fragment refs. */
|
|
14
|
+
fragmentRefs?: boolean
|
|
15
|
+
/** Experimental native ViewTransition animations. Opt-in until snapshot parity is complete. */
|
|
16
|
+
viewTransitions?: boolean
|
|
17
|
+
/**
|
|
18
|
+
* `createPortal`. When `false`, portal elements render in place as a
|
|
19
|
+
* Fragment (the `container` prop is ignored). `renderPortal` and its
|
|
20
|
+
* deps are stripped from the bundle.
|
|
21
|
+
*/
|
|
22
|
+
portal?: boolean
|
|
23
|
+
/**
|
|
24
|
+
* `createContext` / `useContext` / `<Provider>` / `<Consumer>`. When
|
|
25
|
+
* `false`, Providers render as Fragments (value never propagates),
|
|
26
|
+
* Consumers invoke their function-children with the context's default
|
|
27
|
+
* value, and `useContext` returns the default. Provider-walk logic and
|
|
28
|
+
* `renderProvider` are stripped.
|
|
29
|
+
*/
|
|
30
|
+
context?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* `<Suspense>` boundaries + streaming hydration. When `false`, Suspense
|
|
33
|
+
* elements render as Fragments (children mount inline, `fallback` is
|
|
34
|
+
* ignored). Thrown thenables still schedule a re-render on settle, so
|
|
35
|
+
* eventual consistency works, just no fallback UI during the pending
|
|
36
|
+
* window. Boundary-handler stack and hydration integration are stripped.
|
|
37
|
+
*/
|
|
38
|
+
suspense?: boolean
|
|
39
|
+
/**
|
|
40
|
+
* `React.memo`. When `false`, memoized components still render but without
|
|
41
|
+
* the prop-equality gate, every parent rerender passes through.
|
|
42
|
+
* `shallowEqual` and the force-rerender bypass are stripped.
|
|
43
|
+
*/
|
|
44
|
+
memo?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* `React.forwardRef`. When `false`, forwardRef components still render but
|
|
47
|
+
* the ref prop isn't forwarded to the inner function. React 19+ treats
|
|
48
|
+
* refs as normal props on function components anyway, so most apps can
|
|
49
|
+
* drop this. The dispatcher save/restore machinery is stripped.
|
|
50
|
+
*/
|
|
51
|
+
forwardRef?: boolean
|
|
52
|
+
/**
|
|
53
|
+
* `React.lazy`. When `false`, lazy elements still resolve if their payload
|
|
54
|
+
* is already available synchronously (e.g. pre-awaited RSC Flight); async
|
|
55
|
+
* resolution throws a clear error. The hydration-deferred-reveal path and
|
|
56
|
+
* Suspense coordination are stripped.
|
|
57
|
+
*/
|
|
58
|
+
lazy?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* Class components (`extends Component`). When `false`, class components
|
|
61
|
+
* still render but only honor the core contract: constructor + `render()`
|
|
62
|
+
* + `setState`. Dropped: `contextType`, `getDerivedStateFromProps`,
|
|
63
|
+
* `shouldComponentUpdate`, `componentDidMount`/`Update`/`WillUnmount`,
|
|
64
|
+
* `getDerivedStateFromError`/`componentDidCatch` (error boundaries).
|
|
65
|
+
*/
|
|
66
|
+
classComponents?: boolean
|
|
67
|
+
/**
|
|
68
|
+
* SSR hydration (`hydrateRoot`). When `false`, `hydrateRoot` throws
|
|
69
|
+
* (use `createRoot` for SPAs). The HydrationCursor / DOM adoption /
|
|
70
|
+
* streaming-boundary coordination / event-replay / scroll-guard
|
|
71
|
+
* machinery is stripped, the biggest single chunk of reducible code.
|
|
72
|
+
*/
|
|
73
|
+
hydration?: boolean
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ResolvedFeatures {
|
|
77
|
+
activity: boolean
|
|
78
|
+
fragmentRefs: boolean
|
|
79
|
+
viewTransitions: boolean
|
|
80
|
+
portal: boolean
|
|
81
|
+
context: boolean
|
|
82
|
+
suspense: boolean
|
|
83
|
+
memo: boolean
|
|
84
|
+
forwardRef: boolean
|
|
85
|
+
lazy: boolean
|
|
86
|
+
classComponents: boolean
|
|
87
|
+
hydration: boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const PRESET_DEFAULTS: Record<RedactPreset, ResolvedFeatures> = {
|
|
91
|
+
// Opt-in: everything off. Turn individual features on via `features`.
|
|
92
|
+
nano: {
|
|
93
|
+
activity: false, fragmentRefs: false, viewTransitions: false,
|
|
94
|
+
portal: false, context: false, suspense: false, memo: false,
|
|
95
|
+
forwardRef: false, lazy: false, classComponents: false, hydration: false,
|
|
96
|
+
},
|
|
97
|
+
// Opt-out: everything on (drop-in React parity). Turn features off via `features`.
|
|
98
|
+
full: {
|
|
99
|
+
activity: true, fragmentRefs: true, viewTransitions: false,
|
|
100
|
+
portal: true, context: true, suspense: true, memo: true,
|
|
101
|
+
forwardRef: true, lazy: true, classComponents: true, hydration: true,
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function resolveFeatures(
|
|
106
|
+
preset: RedactPreset,
|
|
107
|
+
overrides: RedactFeatures,
|
|
108
|
+
): ResolvedFeatures {
|
|
109
|
+
const p = PRESET_DEFAULTS[preset]
|
|
110
|
+
return {
|
|
111
|
+
activity: overrides.activity ?? p.activity,
|
|
112
|
+
fragmentRefs: overrides.fragmentRefs ?? p.fragmentRefs,
|
|
113
|
+
viewTransitions: overrides.viewTransitions ?? p.viewTransitions,
|
|
114
|
+
portal: overrides.portal ?? p.portal,
|
|
115
|
+
context: overrides.context ?? p.context,
|
|
116
|
+
suspense: overrides.suspense ?? p.suspense,
|
|
117
|
+
memo: overrides.memo ?? p.memo,
|
|
118
|
+
forwardRef: overrides.forwardRef ?? p.forwardRef,
|
|
119
|
+
lazy: overrides.lazy ?? p.lazy,
|
|
120
|
+
classComponents: overrides.classComponents ?? p.classComponents,
|
|
121
|
+
hydration: overrides.hydration ?? p.hydration,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Alias map. ORDER MATTERS, Vite's alias matcher uses first-match against
|
|
126
|
+
// prefix, so more-specific specifiers MUST come before less-specific ones.
|
|
127
|
+
// Without this, `react-dom/server` would prefix-match `react-dom` first and
|
|
128
|
+
// resolve to `@tanstack/redact/dom/server` (wrong) instead of
|
|
129
|
+
// `@tanstack/redact/server`.
|
|
130
|
+
//
|
|
131
|
+
// `use-sync-external-store` aliases are here because its CJS-only React 17
|
|
132
|
+
// compat shim does `var React = require('react')`. That survives Vite's
|
|
133
|
+
// pre-bundling intact and explodes in Cloudflare Workers (no `require`).
|
|
134
|
+
// Modern React has `useSyncExternalStore` built-in, and `@tanstack/redact`
|
|
135
|
+
// additionally exports `useSyncExternalStoreWithSelector` so this alias
|
|
136
|
+
// is safe everywhere.
|
|
137
|
+
export const ALIASES: Record<string, string> = {
|
|
138
|
+
// ---- most-specific first ----
|
|
139
|
+
'use-sync-external-store/shim/with-selector': '@tanstack/redact',
|
|
140
|
+
'use-sync-external-store/shim/with-selector.js': '@tanstack/redact',
|
|
141
|
+
'use-sync-external-store/with-selector': '@tanstack/redact',
|
|
142
|
+
'use-sync-external-store/with-selector.js': '@tanstack/redact',
|
|
143
|
+
// Explicit file subpaths (react-aria imports `shim/index.js`). Without these,
|
|
144
|
+
// dev resolves the raw CJS shim and its named ESM import fails.
|
|
145
|
+
'use-sync-external-store/shim/index.js': '@tanstack/redact',
|
|
146
|
+
'use-sync-external-store/index.js': '@tanstack/redact',
|
|
147
|
+
'use-sync-external-store/shim': '@tanstack/redact',
|
|
148
|
+
'use-sync-external-store': '@tanstack/redact',
|
|
149
|
+
|
|
150
|
+
// React drop-in shim targets. Subpaths first.
|
|
151
|
+
'react/jsx-runtime': '@tanstack/redact/jsx-runtime',
|
|
152
|
+
'react/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',
|
|
153
|
+
'react/compiler-runtime': '@tanstack/redact/compiler-runtime',
|
|
154
|
+
'react-dom/profiling': '@tanstack/redact/dom-profiling',
|
|
155
|
+
'react-dom/client': '@tanstack/redact/dom-client',
|
|
156
|
+
'react-dom/server.browser': '@tanstack/redact/server',
|
|
157
|
+
'react-dom/server.bun': '@tanstack/redact/server',
|
|
158
|
+
'react-dom/server.edge': '@tanstack/redact/server',
|
|
159
|
+
'react-dom/server.node': '@tanstack/redact/server',
|
|
160
|
+
'react-dom/static.edge': '@tanstack/redact/server',
|
|
161
|
+
'react-dom/server': '@tanstack/redact/server',
|
|
162
|
+
'react-dom/test-utils': '@tanstack/redact/dom-test-utils',
|
|
163
|
+
'react-dom': '@tanstack/redact/dom',
|
|
164
|
+
react: '@tanstack/redact',
|
|
165
|
+
scheduler: '@tanstack/redact/scheduler',
|
|
166
|
+
|
|
167
|
+
// Self-aliases so Vite resolves `@tanstack/redact/*` imports to the same
|
|
168
|
+
// canonical file path no matter where they originate (worker bundle vs
|
|
169
|
+
// deps_ssr pre-bundle vs source). Without these, Cloudflare's
|
|
170
|
+
// `noExternal: true` worker config inlines one copy while Vite's
|
|
171
|
+
// optimizeDeps pre-bundles another, ending up with two separate
|
|
172
|
+
// ReactSharedInternals instances and a null dispatcher in user hooks.
|
|
173
|
+
// Subpaths first here too.
|
|
174
|
+
'@tanstack/redact/jsx-runtime': '@tanstack/redact/jsx-runtime',
|
|
175
|
+
'@tanstack/redact/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',
|
|
176
|
+
'@tanstack/redact/compiler-runtime': '@tanstack/redact/compiler-runtime',
|
|
177
|
+
'@tanstack/redact/dom-profiling': '@tanstack/redact/dom-profiling',
|
|
178
|
+
'@tanstack/redact/dom-client': '@tanstack/redact/dom-client',
|
|
179
|
+
'@tanstack/redact/dom-test-utils': '@tanstack/redact/dom-test-utils',
|
|
180
|
+
'@tanstack/redact/server': '@tanstack/redact/server',
|
|
181
|
+
'@tanstack/redact/scheduler': '@tanstack/redact/scheduler',
|
|
182
|
+
'@tanstack/redact/dom': '@tanstack/redact/dom',
|
|
183
|
+
'@tanstack/redact': '@tanstack/redact',
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The caller canonicalizes filesystem paths before making this pure ownership decision.
|
|
187
|
+
export function isOwnedRuntimeFeature(id: string, packageRoot: string): boolean {
|
|
188
|
+
const path = id.replaceAll('\\', '/')
|
|
189
|
+
const root = packageRoot.replaceAll('\\', '/').replace(/\/$/, '')
|
|
190
|
+
return path.startsWith(root + '/src/dom/features/') ||
|
|
191
|
+
path.startsWith(root + '/dist/dom/features/')
|
|
192
|
+
}
|
package/src/core/internal.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface Effect {
|
|
|
30
30
|
s?: boolean | undefined; // Store subscriptions run in layout but stay connected in Suspense.
|
|
31
31
|
}
|
|
32
32
|
export interface Fiber {
|
|
33
|
+
br?: boolean; // This boundary is rendering its error recovery tree.
|
|
33
34
|
ix?: number; // Logical child position, including empty slots.
|
|
34
35
|
t: FiberTag; // Tag.
|
|
35
36
|
type: any;
|
|
@@ -80,7 +81,7 @@ export interface FiberRoot {
|
|
|
80
81
|
c: Element | DocumentFragment;
|
|
81
82
|
r: Fiber;
|
|
82
83
|
p: Set<Fiber>;
|
|
83
|
-
s: boolean;
|
|
84
|
+
s: boolean | (() => void); // Development host callbacks carry their own identity.
|
|
84
85
|
u?: (() => void) | undefined;
|
|
85
86
|
er?: Array<{
|
|
86
87
|
error: unknown;
|
package/src/core/types.ts
CHANGED
|
@@ -7,11 +7,12 @@ export const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment')
|
|
|
7
7
|
|
|
8
8
|
export type Key = string | number | null | undefined
|
|
9
9
|
|
|
10
|
+
// Native React declarations omit these runtime protocol fields and the legacy ref accessor.
|
|
10
11
|
export interface ReactElement<P = any, T = any> {
|
|
11
|
-
$$typeof
|
|
12
|
+
$$typeof?: typeof REACT_ELEMENT_TYPE
|
|
12
13
|
type: T
|
|
13
14
|
key: string | null
|
|
14
|
-
ref
|
|
15
|
+
ref?: any
|
|
15
16
|
props: P
|
|
16
17
|
}
|
|
17
18
|
|
package/src/dom/dom.ts
CHANGED
|
@@ -8,7 +8,7 @@ const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
8
8
|
const IDL_ATTRS = /^(value|checked|selected|disabled|multiple|muted|readonly)$/;
|
|
9
9
|
export const isSvgElement = (el: Element): boolean => (el.namespaceURI === SVG_NS);
|
|
10
10
|
export function setProp(el: Element, name: string, next: any, prev: any, isSvg: boolean): void {
|
|
11
|
-
if (isReservedProp(name))
|
|
11
|
+
if (isReservedProp(name) || name === 'autoFocus')
|
|
12
12
|
return;
|
|
13
13
|
// These names need no alias or boolean-attribute normalization.
|
|
14
14
|
if (/^(aria|data)-./.test(name)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { devToolsMetadata } from '../../../core/devtools';
|
|
2
2
|
import { resolveClassProps } from '../../../core/class-props';
|
|
3
|
-
import { invokeCommit, stageCommit
|
|
3
|
+
import { invokeCommit, stageCommit } from '../../reconcile';
|
|
4
4
|
import { installRenderer, reconcileRaw, childrenToArray, scheduleUpdate, scheduleLifecycle, isThenable, handleSuspended, handleErrorInRender, readContext, attachRef, syncRefIfChanged, isActivityHidden, layoutIsDisconnected, RenderErrorCapture, handleCommitError, } from '../../reconcile';
|
|
5
5
|
import { checkpointCommit, rewindCommit, queueBeforeMutation, queueMutation } from '../../commit';
|
|
6
6
|
import { FiberTag, type Fiber, type ReactNode } from '../../../core';
|
|
@@ -98,47 +98,39 @@ function renderClass(fiber: Fiber): void {
|
|
|
98
98
|
}
|
|
99
99
|
instance.props = props;
|
|
100
100
|
}
|
|
101
|
-
// Errors from
|
|
102
|
-
//
|
|
103
|
-
if (captured) recoveringBoundaries.add(fiber);
|
|
101
|
+
// Errors from recovery belong to an enclosing boundary. Reuse the same
|
|
102
|
+
// render path for the first attempt and its fallback so state stays aligned.
|
|
104
103
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
let rendered: ReactNode = captured && !Ctor.getDerivedStateFromError ? null : didRender ? instance.render() : fiber.b?.r;
|
|
111
|
-
fiber.b = { ...(fiber.b ?? {}), r: rendered };
|
|
112
|
-
const canCatch = Ctor.getDerivedStateFromError || instance.componentDidCatch;
|
|
113
|
-
if (canCatch)
|
|
114
|
-
fiber.b.b = Ctor;
|
|
115
|
-
if (canCatch && fiber.r)
|
|
116
|
-
fiber.r.eb = true;
|
|
117
|
-
const checkpoint = canCatch ? checkpointCommit(fiber) : -1;
|
|
118
|
-
try {
|
|
119
|
-
reconcileRaw(fiber, rendered);
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
if (!(error instanceof RenderErrorCapture) || error.b !== fiber)
|
|
123
|
-
throw error;
|
|
124
|
-
rewindCommit(checkpoint);
|
|
125
|
-
captured = error;
|
|
126
|
-
recoveringBoundaries.add(fiber);
|
|
127
|
-
didRender = true;
|
|
128
|
-
if (Ctor.getDerivedStateFromError) {
|
|
129
|
-
const update = Ctor.getDerivedStateFromError(error.e);
|
|
104
|
+
for (;;) {
|
|
105
|
+
fiber.br = !!captured;
|
|
106
|
+
if (captured && Ctor.getDerivedStateFromError) {
|
|
107
|
+
const update = Ctor.getDerivedStateFromError(captured.e);
|
|
130
108
|
if (update != null)
|
|
131
109
|
instance.state = { ...instance.state, ...update };
|
|
132
|
-
rendered = instance.render();
|
|
133
110
|
}
|
|
134
|
-
|
|
135
|
-
rendered = null;
|
|
111
|
+
const rendered: ReactNode = captured && !Ctor.getDerivedStateFromError ? null : didRender ? instance.render() : fiber.b?.r;
|
|
136
112
|
fiber.b = { ...(fiber.b ?? {}), r: rendered };
|
|
137
|
-
|
|
113
|
+
const canCatch = Ctor.getDerivedStateFromError || instance.componentDidCatch;
|
|
114
|
+
if (canCatch)
|
|
115
|
+
fiber.b.b = Ctor;
|
|
116
|
+
if (canCatch && fiber.r)
|
|
117
|
+
fiber.r.eb = true;
|
|
118
|
+
const checkpoint = canCatch ? checkpointCommit(fiber) : -1;
|
|
119
|
+
try {
|
|
120
|
+
reconcileRaw(fiber, rendered);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (captured || !(error instanceof RenderErrorCapture) || error.b !== fiber)
|
|
125
|
+
throw error;
|
|
126
|
+
rewindCommit(checkpoint);
|
|
127
|
+
captured = error;
|
|
128
|
+
didRender = true;
|
|
129
|
+
}
|
|
138
130
|
}
|
|
139
131
|
}
|
|
140
132
|
finally {
|
|
141
|
-
|
|
133
|
+
fiber.br = false;
|
|
142
134
|
}
|
|
143
135
|
fiber.m = props;
|
|
144
136
|
const state = instance.state;
|