Page-scope query runs before globally-scoped queries

My application has several js query that are page-scoped and set to run on page load with a 1000ms delay. They rely on globally-scoped query data and the loading of page components in order to not error out.

Scenario : When I refresh my browser while on a particular page in my app....those page-scoped js query run before any globally-scoped variable and therefore error out. Not only do they not run after the globally-scoped queries but they also don't run on the 1000ms delay that I have setup within their respective advanced tab.

Scenario 2: If I click a nav component to navigate between pages those same js queries errror out as they do in scencario 1, but then run again (as expected and successfuly) after the globally-scoped queries and 1000ms timing delay (without any trigger).

In the retool documentation it says that page-scoped queries run after globally-scoped queries AND I'd expect the 1000ms delay to apply either way.

Page-Scoped JS Queries with this strange behavior:
setFilterPrefs_REGISTRATIONS
setFilterPrefs_PARTICIPANTS
setFilterPrefs_EVENTS
setFilterPrefs_FORMS




Ayni - Ceremony Management.json (772.0 KB)

Hi @Marcelo_Fernando_Vigo,
Did you send me the correct json? Because I don't see any of the following queries:

setFilterPrefs_REGISTRATIONS
setFilterPrefs_PARTICIPANTS
setFilterPrefs_EVENTS
setFilterPrefs_FORMS

What I DO see is:

but none of them have anything set in their Advanced tabs.

However, in thinking about how you have your queries set up, I don't think the global queries will run simply because you switch pages. The global queries will only run on page load. I believe you will have to trigger the global queries in your page queries before you access the global data from those queries. Do so using an await globalQuerry.trigger() at the top of your page query. Then the global data will be available in the page query.

Let me know if this works for you. :smile:

I sent you the json that was generated by retool.....not sure how well that functionality works though...it's my first time using it. Perhaps it didn't come through ok. Or perhaps you aren't on retool cloud but a self-host?

I can assure you though....on my end the advanced tab has "Run this query on page load" checked for the query in question.

All my global queries that are needed on page load are triggered in a gobally-scoped js query (initPage) that chains them in the order needed. So my concern isn't whether or not the global queries are running....my concern is that 1) gloabally-scoped queries are not running first on the first page load (they do on subsqequent page changes via the navigation component) and 2) i have a 1 second delay on page load for the query in question so it can't possibly be the first thing that runs ever.

@Marcelo_Fernando_Vigo,
I think I have found at least one issue that is causing your problem of these page queries running immediately. In your init function, you run setUserPrefTrigger.trigger() which sets the global variable triggerUserFilterPrefs. This variable is set as one of the Watched inputs in the Advanced tab for the four queries that you list. As a result, when that variable changes, these queries are run automatically and will not be subject to the 1 second delay on page load. If you can remove that variable from the Watched inputs field, these queries would not run automatically on page refresh.

I don't know why but the JSON file I first uploaded doesn't seem to reflect what I see. Those queries on my end do not have any watched inputs. All they have enabled on the advanced tab on my end is the pageload checkbox and a pageload delay variable.

Maybe the json below that I just created will reflect what I actually see?

Ayni - Ceremony Management (2).json (832.3 KB)

@Marcelo_Fernando_Vigo ,
Found the issue I think. When you set your delay time, you are using the global variable, filterLoadDelayMS. I believe that when the page loads, it reads this variable immediately, and since your queries depend on this variable, it runs them automatically. If you instead just enter 1000 in the Page load delay (ms) field, it works.

Hi lindakwoo,

Thanks for trying but that didn't change anything. The issue seems to be that if I am already on a page and i refresh the browser.....the "run this query on page load" doesn't work for page-scoped js queries. Not sure why that would be the case since on a browser refresh I'd expect any and all queries marked as "run this query on page load" to run whether globally or page-scoped.

I can't be the only person to have noticed this strange behavior?

-Marcelo

Correction! That did fix it in a way....I just had to increase the number from 1000 to 1500. Why would a global variable not be available to the advanced tab settings though?

@Marcelo_Fernando_Vigo
It is available. The issue is that when the delay is set using a global variable, Retool treats the query as dependent on that variable. On page load, the query immediately runs because it reads the global variable, and Retool interprets that as a change.

In other words, even though the value hasn't truly changed, the act of referencing the global variable causes Retool to re-run the query immediately without respecting the intended delay. It's the dependency on the variable that triggers the query run, not a true value change.