1
- import { version , type ReactNode , type JSX } from 'react'
1
+ import * as React from 'react'
2
2
import Reconciler from 'react-reconciler'
3
- import { NoEventPriority , DefaultEventPriority , ConcurrentRoot } from 'react-reconciler/constants.js'
3
+ import {
4
+ // NoEventPriority,
5
+ ContinuousEventPriority ,
6
+ DiscreteEventPriority ,
7
+ DefaultEventPriority ,
8
+ ConcurrentRoot ,
9
+ } from 'react-reconciler/constants.js'
10
+
11
+ // @ts -ignore
12
+ const __DEV__ = /* @__PURE__ */ ( ( ) => typeof process !== 'undefined' && process . env . NODE_ENV !== 'production' ) ( )
4
13
5
14
// TODO: upstream to DefinitelyTyped for React 19
6
15
// https://github.com/facebook/react/issues/28956
7
16
type EventPriority = number
8
17
9
- const createReconciler = Reconciler as unknown as <
18
+ function createReconciler <
10
19
Type ,
11
20
Props ,
12
21
Container ,
@@ -56,6 +65,7 @@ const createReconciler = Reconciler as unknown as <
56
65
// Undocumented
57
66
// https://github.com/facebook/react/pull/26722
58
67
NotPendingTransition : TransitionStatus | null
68
+ HostTransitionContext : React . Context < TransitionStatus >
59
69
// https://github.com/facebook/react/pull/28751
60
70
setCurrentUpdatePriority ( newPriority : EventPriority ) : void
61
71
getCurrentUpdatePriority ( ) : EventPriority
@@ -66,6 +76,11 @@ const createReconciler = Reconciler as unknown as <
66
76
requestPostPaintCallback ( callback : ( time : number ) => void ) : void
67
77
// https://github.com/facebook/react/pull/26025
68
78
shouldAttemptEagerTransition ( ) : boolean
79
+ // https://github.com/facebook/react/pull/31528
80
+ trackSchedulerEvent ( ) : void
81
+ // https://github.com/facebook/react/pull/31008
82
+ resolveEventType ( ) : null | string
83
+ resolveEventTimeStamp ( ) : number
69
84
70
85
/**
71
86
* This method is called during render to determine if the Host Component type and props require some kind of loading process to complete before committing an update.
@@ -93,12 +108,20 @@ const createReconciler = Reconciler as unknown as <
93
108
*/
94
109
waitForCommitToBeReady ( ) : ( ( initiateCommit : Function ) => Function ) | null
95
110
} ,
96
- ) => Reconciler . Reconciler < Container , Instance , TextInstance , SuspenseInstance , PublicInstance >
111
+ ) : Reconciler . Reconciler < Container , Instance , TextInstance , SuspenseInstance , PublicInstance > {
112
+ const reconciler = Reconciler ( config as any )
113
+
114
+ reconciler . injectIntoDevTools ( {
115
+ bundleType : __DEV__ ? 1 : 0 ,
116
+ rendererPackageName : 'react-nil' ,
117
+ version : React . version ,
118
+ } )
97
119
98
- declare module 'react-reconciler/constants.js' {
99
- const NoEventPriority = 0
120
+ return reconciler as any
100
121
}
101
122
123
+ const NoEventPriority = 0
124
+
102
125
export interface NilNode < P = Record < string , unknown > > {
103
126
type : string
104
127
props : P
@@ -117,8 +140,8 @@ interface HostConfig {
117
140
textInstance : NilNode
118
141
suspenseInstance : NilNode
119
142
hydratableInstance : never
120
- formInstance : never
121
143
publicInstance : null
144
+ formInstance : never
122
145
hostContext : { }
123
146
childSet : never
124
147
timeoutHandle : number
@@ -142,7 +165,7 @@ const NO_CONTEXT: HostConfig['hostContext'] = {}
142
165
143
166
let currentUpdatePriority : number = NoEventPriority
144
167
145
- const reconciler = createReconciler <
168
+ const reconciler = /* @__PURE__ */ createReconciler <
146
169
HostConfig [ 'type' ] ,
147
170
HostConfig [ 'props' ] ,
148
171
HostConfig [ 'container' ] ,
@@ -159,6 +182,7 @@ const reconciler = createReconciler<
159
182
HostConfig [ 'TransitionStatus' ]
160
183
> ( {
161
184
isPrimaryRenderer : false ,
185
+ warnsIfNotActing : false ,
162
186
supportsMutation : true ,
163
187
supportsPersistence : false ,
164
188
supportsHydration : false ,
@@ -182,70 +206,104 @@ const reconciler = createReconciler<
182
206
getChildHostContext : ( ) => NO_CONTEXT ,
183
207
shouldSetTextContent : ( ) => false ,
184
208
finalizeInitialChildren : ( ) => false ,
185
- commitUpdate : ( instance , _ , __ , props ) => ( instance . props = getInstanceProps ( props ) ) ,
209
+ commitUpdate : ( instance , _type , _prevProps , nextProps ) => ( instance . props = getInstanceProps ( nextProps ) ) ,
186
210
commitTextUpdate : ( instance , _ , value ) => ( instance . props . value = value ) ,
187
211
prepareForCommit : ( ) => null ,
188
212
resetAfterCommit ( ) { } ,
189
213
preparePortalMount ( ) { } ,
190
214
clearContainer : ( container ) => ( container . head = null ) ,
191
- warnsIfNotActing : false ,
192
215
getInstanceFromNode : ( ) => null ,
193
216
beforeActiveInstanceBlur ( ) { } ,
194
217
afterActiveInstanceBlur ( ) { } ,
195
218
detachDeletedInstance ( ) { } ,
196
219
prepareScopeUpdate ( ) { } ,
197
220
getInstanceFromScope : ( ) => null ,
198
- setCurrentUpdatePriority ( newPriority ) {
221
+ shouldAttemptEagerTransition : ( ) => false ,
222
+ trackSchedulerEvent : ( ) => { } ,
223
+ resolveEventType : ( ) => null ,
224
+ resolveEventTimeStamp : ( ) => - 1.1 ,
225
+ requestPostPaintCallback ( ) { } ,
226
+ maySuspendCommit : ( ) => false ,
227
+ preloadInstance : ( ) => true , // true indicates already loaded
228
+ startSuspendingCommit ( ) { } ,
229
+ suspendInstance ( ) { } ,
230
+ waitForCommitToBeReady : ( ) => null ,
231
+ NotPendingTransition : null ,
232
+ HostTransitionContext : /* @__PURE__ */ React . createContext < HostConfig [ 'TransitionStatus' ] > ( null ) ,
233
+ setCurrentUpdatePriority ( newPriority : number ) {
199
234
currentUpdatePriority = newPriority
200
235
} ,
201
236
getCurrentUpdatePriority ( ) {
202
237
return currentUpdatePriority
203
238
} ,
204
239
resolveUpdatePriority ( ) {
205
- return currentUpdatePriority || DefaultEventPriority
206
- } ,
207
- shouldAttemptEagerTransition ( ) {
208
- return false
209
- } ,
210
- requestPostPaintCallback ( ) { } ,
211
- maySuspendCommit ( ) {
212
- return false
213
- } ,
214
- preloadInstance ( ) {
215
- return true // true indicates already loaded
216
- } ,
217
- startSuspendingCommit ( ) { } ,
218
- suspendInstance ( ) { } ,
219
- waitForCommitToBeReady ( ) {
220
- return null
240
+ if ( currentUpdatePriority !== NoEventPriority ) return currentUpdatePriority
241
+
242
+ switch ( typeof window !== 'undefined' && window . event ?. type ) {
243
+ case 'click' :
244
+ case 'contextmenu' :
245
+ case 'dblclick' :
246
+ case 'pointercancel' :
247
+ case 'pointerdown' :
248
+ case 'pointerup' :
249
+ return DiscreteEventPriority
250
+ case 'pointermove' :
251
+ case 'pointerout' :
252
+ case 'pointerover' :
253
+ case 'pointerenter' :
254
+ case 'pointerleave' :
255
+ case 'wheel' :
256
+ return ContinuousEventPriority
257
+ default :
258
+ return DefaultEventPriority
259
+ }
221
260
} ,
222
- NotPendingTransition : null ,
223
261
resetFormInstance ( ) { } ,
224
262
} )
225
263
226
- // Inject renderer meta into devtools
227
- const isProd = typeof process === 'undefined' || process . env ?. [ 'NODE_ENV' ] === 'production'
228
- reconciler . injectIntoDevTools ( {
229
- findFiberByHostInstance : ( ) => null ,
230
- bundleType : isProd ? 0 : 1 ,
231
- version,
232
- rendererPackageName : 'react-nil' ,
233
- } )
264
+ /**
265
+ * Force React to flush any updates inside the provided callback synchronously and immediately.
266
+ */
267
+ export function flushSync < R > ( fn : ( ) => R ) : R {
268
+ return reconciler . flushSync ( fn )
269
+ }
270
+
271
+ // Report when an error was detected in a previous render
272
+ // https://github.com/facebook/react/pull/23207
273
+ const logRecoverableError = /* @__PURE__ */ ( ( ) =>
274
+ typeof reportError === 'function'
275
+ ? // In modern browsers, reportError will dispatch an error event,
276
+ // emulating an uncaught JavaScript error.
277
+ reportError
278
+ : // In older browsers and test environments, fallback to console.error.
279
+ console . error ) ( )
234
280
235
281
const container : HostContainer = { head : null }
236
- const root = reconciler . createContainer ( container , ConcurrentRoot , null , false , null , '' , console . error , null )
282
+ const root = /* @__PURE__ */ ( reconciler as any ) . createContainer (
283
+ container , // containerInfo
284
+ ConcurrentRoot , // tag
285
+ null , // hydrationCallbacks
286
+ false , // isStrictMode
287
+ null , // concurrentUpdatesByDefaultOverride
288
+ '' , // identifierPrefix
289
+ logRecoverableError , // onUncaughtError
290
+ logRecoverableError , // onCaughtError
291
+ logRecoverableError , // onRecoverableError
292
+ null , // transitionCallbacks
293
+ )
237
294
238
295
/**
239
296
* Renders a React element into a `null` root.
240
297
*/
241
- export function render ( element : ReactNode ) : HostContainer {
298
+ export function render ( element : React . ReactNode ) : HostContainer {
242
299
reconciler . updateContainer ( element , root , null , undefined )
243
300
return container
244
301
}
245
302
246
303
/**
247
304
* Renders a React element into a foreign {@link HostContainer}.
248
305
*/
249
- export function createPortal ( element : ReactNode , container : HostContainer ) : JSX . Element {
306
+ export function createPortal ( element : React . ReactNode , container : HostContainer ) : React . JSX . Element {
307
+ // @ts -expect-error
250
308
return < > { reconciler . createPortal ( element , container , null , null ) } </ >
251
309
}
0 commit comments