@@ -47,7 +47,7 @@ function createStreamableUI(initialValue?: React.ReactNode) {
4747 }
4848 warnUnclosedStream ( ) ;
4949
50- return {
50+ const streamable = {
5151 /**
5252 * The value of the streamable UI. This can be returned from a Server Action and received by the client.
5353 */
@@ -61,7 +61,7 @@ function createStreamableUI(initialValue?: React.ReactNode) {
6161 // There is no need to update the value if it's referentially equal.
6262 if ( value === currentValue ) {
6363 warnUnclosedStream ( ) ;
64- return ;
64+ return streamable ;
6565 }
6666
6767 const resolvable = createResolvablePromise ( ) ;
@@ -72,6 +72,8 @@ function createStreamableUI(initialValue?: React.ReactNode) {
7272 reject = resolvable . reject ;
7373
7474 warnUnclosedStream ( ) ;
75+
76+ return streamable ;
7577 } ,
7678 /**
7779 * This method is used to append a new UI node to the end of the old one.
@@ -100,6 +102,8 @@ function createStreamableUI(initialValue?: React.ReactNode) {
100102 reject = resolvable . reject ;
101103
102104 warnUnclosedStream ( ) ;
105+
106+ return streamable ;
103107 } ,
104108 /**
105109 * This method is used to signal that there is an error in the UI stream.
@@ -113,6 +117,8 @@ function createStreamableUI(initialValue?: React.ReactNode) {
113117 }
114118 closed = true ;
115119 reject ( error ) ;
120+
121+ return streamable ;
116122 } ,
117123 /**
118124 * This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
@@ -129,11 +135,15 @@ function createStreamableUI(initialValue?: React.ReactNode) {
129135 closed = true ;
130136 if ( args . length ) {
131137 resolve ( { value : args [ 0 ] , done : true } ) ;
132- return ;
138+ return streamable ;
133139 }
134140 resolve ( { value : currentValue , done : true } ) ;
141+
142+ return streamable ;
135143 } ,
136144 } ;
145+
146+ return streamable ;
137147}
138148
139149const STREAMABLE_VALUE_INTERNAL_LOCK = Symbol ( 'streamable.value.lock' ) ;
@@ -276,7 +286,7 @@ function createStreamableValueImpl<T = any, E = any>(initialValue?: T) {
276286 currentValue = value ;
277287 }
278288
279- return {
289+ const streamable = {
280290 /**
281291 * @internal This is an internal lock to prevent the value from being
282292 * updated by the user.
@@ -306,6 +316,8 @@ function createStreamableValueImpl<T = any, E = any>(initialValue?: T) {
306316 resolvePrevious ( createWrapped ( ) ) ;
307317
308318 warnUnclosedStream ( ) ;
319+
320+ return streamable ;
309321 } ,
310322 /**
311323 * This method is used to append a delta string to the current value. It
@@ -351,6 +363,8 @@ function createStreamableValueImpl<T = any, E = any>(initialValue?: T) {
351363 resolvePrevious ( createWrapped ( ) ) ;
352364
353365 warnUnclosedStream ( ) ;
366+
367+ return streamable ;
354368 } ,
355369 /**
356370 * This method is used to signal that there is an error in the value stream.
@@ -368,6 +382,8 @@ function createStreamableValueImpl<T = any, E = any>(initialValue?: T) {
368382 currentPromise = undefined ;
369383
370384 resolvable . resolve ( { error } ) ;
385+
386+ return streamable ;
371387 } ,
372388 /**
373389 * This method marks the value as finalized. You can either call it without
@@ -389,12 +405,16 @@ function createStreamableValueImpl<T = any, E = any>(initialValue?: T) {
389405 if ( args . length ) {
390406 updateValueStates ( args [ 0 ] ) ;
391407 resolvable . resolve ( createWrapped ( ) ) ;
392- return ;
408+ return streamable ;
393409 }
394410
395411 resolvable . resolve ( { } ) ;
412+
413+ return streamable ;
396414 } ,
397415 } ;
416+
417+ return streamable ;
398418}
399419
400420export { createStreamableUI , createStreamableValue } ;
0 commit comments