I’ve been stuck with with an “Error resolving function params” when registering a custom function of any kind (Query, Mutant, Custom code function) when I either, load the page in browser via localhost, or refresh the interactive mode arena. It works normally when refreshing the browser page and loading into the studio.plasmic.app editor for the first time. I found the root cause to be that one of my custom query gets canceled on the arena refresh. The other queries don’t seem to work in the console either though. Maybe it’s being canceled because I’m using “include” on credentials? If so, I need a way around this.
I do mean by credentials: ‘include’ in my fetch request. I refreshed my data and it still doesn’t work with the same behavior as before.
I did some more testing and found out that using include is indeed the cause of the issue since using ’omit’ and ’same-origin’ work fine. However, my backend needed cookies or another way to authenticate without being shown client-side.
With further testing, I discovered this error when using server functions as in ’use server’ on the top of my functions source.
Nevermind the 3rd paragraph, ’omit’ and ’same-origin’ don’t work. Executing the request again in the editor is what caused the request be successful. Doing an Arena refresh when using ’omit’ or ’same-origin’ both lead to the same request cancelation.
@samuel_pullman , new discovery! After a 3rd refresh, the data queries that originally wouldn’t work because of a “failed to fetch” or a “the global scope is shutting down” error work again while the other data queries dependent on the information of the independent queries ("failed to fetch”, “the global scope is shutting down”) don’t work.
Hi @match_stickn, you actually should be able to reference $q and $ctx in your queries. Since you set credentials: ‘omit’ and same-origin have a similar issue, this may be an editor bug. I would have suggested to try bearer auth instead of cookies, or make sure your sever has Access-Control-Allow-Origin: https://studio.plasmic.app , but I don’t think that will solve your problem.
I’m still looking into it, but haven’t been able to reproduce the error yet.
That’s odd, the data tokens update should have rolled out a day before your message. Previously I could reproduce it easily, and now data tokens are working fine for me in custom code queries.
Can you try a hard reset of the studio, and maybe clear the cache? It shouldn’t be necessary, but maybe your browser is still serving an older version. Also, you can try deleting the $dataTokens reference and adding it back.
The $dataTokens update is finally working for me. The fix on my end was to use a copy of the nextauth example and running my code from there. Apparently I had a broken node module that was in a lock file.
Running custom functions that are queries with the nextauth example setup works stably most of the time as of writing this. Refreshing in the editor does cause a failed to fetch error for every second time refreshing, however loading the app in preview or visiting the custom host website does load the page without errors.
When I added another data query that was dependent on the return value of another one, everything broke like before. It seems to me that when I used a new data query’s return value as a param for another data query, something breaks that persists beyond program execution.
For right now, navigating to my projects page and restarting my code execution on my custom app host fixes the “$dataToken is not defined" bug that happens when mixing data query return and params.
My app works with the custom code queries fixed, but the original bug isn’t solved.
Thanks again for working with me.