Unintuitive transformer behavior PSA

I've run across an issue with transformers and I can't verify if it is intended behavior or a bug so here's a PSA for anyone else who might run into this problem.

The setup:

Here's a simple scenario, I have a transformer that is returning a default value that is JSON, in that JSON I was using the uuid.v4() function to return an ID for this new JSON object.

return {
 "uuid": {{ uuid.v4() }}
 ... rest of the object, which is all static values
}

It's a pretty straightforward transformer. Now this is getting used within a javascript query to add this new object to a localStorage value

const defaultValue = defaultObject.value;
const currentItems = localStorage.values.workingItems;
currentItems.push(defaultValue)
localStorage.set('workingItems', currentItems);

What I would have expected to happen is that each time I execute this javascript query the item added to the array has a new UUID. But that is not what happens, each time it runs it's the same UUID.

Additionally what's weird is that each time I preview the defaultValue transformer I get a result with a different UUID. So its like the javascript query is using a cached version of the transformer and not actually evaluating the data within the transformer. To work around this I've done this

const defaultValue = defaultObject.value;
const currentItems = localStorage.values.workingItems;
defaultValue.uuuid = uuid.v4();
currentItems.push(defaultValue)
localStorage.set('workingItems', currentItems);

Now every time the javascript query runs I get a new UUID for the value that is inserted in the array.

Has anyone else encountered other behavior like this with transformers? Is there documentation somewhere that details why this appears to be happening?

I think it's a known "issue" with transformers and how they're triggered - it's slightly different to a JS Query
This thread may help

1 Like