Data queries work only in editor

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’ve attached screenshots below.

First Load:

Arena Refresh:

Localhost Page Load:

Network Brower Console:

Thanks for any help possible.

Hi @match_stickn, can you provide your project ID? I’ll look into the error.

Just to be clear, by include you mean you’re doing something like this?

fetch('https://test.com', {
  method: 'GET',
  credentials: 'include'
})

It’s possible credentials: 'include' is the cause. Can you try “Refresh data” in the Studio and let me know if you get the same error?

Here is my project id: 1CJT6198cXBUNWibAE7REA

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.

This error also behaves the same way as the previous error mentioned in the original post.

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.

GetUserByEmail2 is just a byproduct of testing.

I also found that the remote address isn’t sent in http requests that fail.

WORKING:

NOT WORKING:

I think I found the reason

I’m using $ctx and other $q states.

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.

Alright, I will revoke the solution tag I put on my previous message

I see this too now @samuel_pullman , I was using available data contexts in a custom code query (not custom function) that came back with this:

Manually typing in the value that localBackendUrl is assigned to works fine.

I haven’t figured out the original issue yet, the the $dataTokens bug should be fixed now.

Have you rolled out the update yet?

I still have trouble with $dataTokens, I’m starting to think that both of these bugs have to do with my developer enviornment.

It still doesn’t work.

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.