@tanstack/redact 0.0.3 → 0.0.5

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/src/react/memo.ts CHANGED
@@ -1,21 +1,37 @@
1
+ import type { ReactElement, ReactNode, Ref } from '../core'
2
+
1
3
  export const REACT_MEMO_TYPE = Symbol.for('react.memo')
2
4
  export const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref')
3
5
  export const REACT_LAZY_TYPE = Symbol.for('react.lazy')
4
6
 
7
+ // Component-shaped return type so JSX usage of memo/forwardRef/lazy results
8
+ // type-checks. The runtime value is a `$$typeof`-tagged record that the
9
+ // reconciler recognizes via type-matchers; the cast lets TypeScript treat
10
+ // it as a callable component at JSX sites without changing what the runtime
11
+ // actually does. `children` is included for the common
12
+ // `<Comp>...</Comp>` form even when the inner P doesn't list it.
13
+ export type ExoticComponent<P> = ((
14
+ props: P & { children?: ReactNode; ref?: any; key?: any },
15
+ ) => ReactElement | null) & {
16
+ readonly $$typeof: symbol
17
+ }
18
+
5
19
  export function memo<P>(
6
20
  type: (props: P) => any,
7
21
  areEqual?: (prev: Readonly<P>, next: Readonly<P>) => boolean,
8
- ) {
9
- return { $$typeof: REACT_MEMO_TYPE, type, compare: areEqual ?? null }
22
+ ): ExoticComponent<P> {
23
+ return { $$typeof: REACT_MEMO_TYPE, type, compare: areEqual ?? null } as unknown as ExoticComponent<P>
10
24
  }
11
25
 
12
26
  export function forwardRef<R, P = {}>(
13
27
  render: (props: P, ref: { current: R | null } | ((r: R | null) => void) | null) => any,
14
- ) {
15
- return { $$typeof: REACT_FORWARD_REF_TYPE, render }
28
+ ): ExoticComponent<P & { ref?: Ref<R> }> {
29
+ return { $$typeof: REACT_FORWARD_REF_TYPE, render } as unknown as ExoticComponent<P & { ref?: Ref<R> }>
16
30
  }
17
31
 
18
- export function lazy<T extends { default: any }>(ctor: () => Promise<T>) {
32
+ export function lazy<T extends { default: any }>(ctor: () => Promise<T>): ExoticComponent<
33
+ T['default'] extends (props: infer P) => any ? P : {}
34
+ > {
19
35
  const payload = {
20
36
  status: -1 as -1 | 0 | 1 | 2,
21
37
  result: undefined as any,
@@ -41,5 +57,5 @@ export function lazy<T extends { default: any }>(ctor: () => Promise<T>) {
41
57
  p.result = thenable
42
58
  throw thenable
43
59
  },
44
- }
60
+ } as unknown as ExoticComponent<T['default'] extends (props: infer P) => any ? P : {}>
45
61
  }
@@ -40,10 +40,10 @@ export interface SuspendedBoundary {
40
40
 
41
41
  export interface WalkOptions {
42
42
  emit: (chunk: string) => void
43
- onSuspend?: (boundary: SuspendedBoundary) => void
43
+ onSuspend?: ((boundary: SuspendedBoundary) => void) | undefined
44
44
  nextBoundaryId: () => number
45
- bootstrapped?: boolean
46
- isBoundaryResolution?: boolean
45
+ bootstrapped?: boolean | undefined
46
+ isBoundaryResolution?: boolean | undefined
47
47
  /**
48
48
  * Tracks whether the most recent emission within the *current text flow*
49
49
  * ended with a text node. When the next emission is also text, we emit a
package/src/vite/index.ts CHANGED
@@ -164,6 +164,7 @@ const ALIASES: Record<string, string> = {
164
164
  // React drop-in shim targets. Subpaths first.
165
165
  'react/jsx-runtime': '@tanstack/redact/jsx-runtime',
166
166
  'react/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',
167
+ 'react/compiler-runtime': '@tanstack/redact/compiler-runtime',
167
168
  'react-dom/client': '@tanstack/redact/dom-client',
168
169
  'react-dom/server': '@tanstack/redact/server',
169
170
  'react-dom/test-utils': '@tanstack/redact/dom-test-utils',
@@ -180,6 +181,7 @@ const ALIASES: Record<string, string> = {
180
181
  // Subpaths first here too.
181
182
  '@tanstack/redact/jsx-runtime': '@tanstack/redact/jsx-runtime',
182
183
  '@tanstack/redact/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',
184
+ '@tanstack/redact/compiler-runtime': '@tanstack/redact/compiler-runtime',
183
185
  '@tanstack/redact/dom-client': '@tanstack/redact/dom-client',
184
186
  '@tanstack/redact/dom-test-utils': '@tanstack/redact/dom-test-utils',
185
187
  '@tanstack/redact/server': '@tanstack/redact/server',