File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
packages/core/src/v3/utils
references/hello-world/src/trigger Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,15 @@ interface ReplacerOptions {
400400}
401401
402402function makeSafeReplacer ( options ?: ReplacerOptions ) {
403+ const seen = new WeakSet < any > ( ) ;
404+
403405 return function replacer ( key : string , value : any ) {
406+ if ( typeof value === "object" && value !== null ) {
407+ if ( seen . has ( value ) ) {
408+ return "[Circular]" ;
409+ }
410+ seen . add ( value ) ;
411+ }
404412 // Check if the key should be filtered out
405413 if ( options ?. filteredKeys ?. includes ( key ) ) {
406414 return undefined ;
Original file line number Diff line number Diff line change @@ -301,3 +301,30 @@ export const resourceMonitorTest = task({
301301 } ;
302302 } ,
303303} ) ;
304+
305+ export const circularReferenceTask = task ( {
306+ id : "circular-reference" ,
307+ run : async ( payload : { message : string } , { ctx } ) => {
308+ logger . info ( "Hello, world from the circular reference task" , { message : payload . message } ) ;
309+
310+ // Create an object
311+ const user = {
312+ name : "Alice" ,
313+ details : {
314+ age : 30 ,
315+ email : "alice@example.com" ,
316+ } ,
317+ } ;
318+
319+ // Create the circular reference
320+ // @ts -expect-error - This is a circular reference
321+ user . details . user = user ;
322+
323+ // Now user.details.user points back to the user object itself
324+ // This creates a circular reference that standard JSON can't handle
325+
326+ return {
327+ user,
328+ } ;
329+ } ,
330+ } ) ;
You can’t perform that action at this time.
0 commit comments