Timing and Page Lifecycle - On Initialization Action

I'm having a problem where on a Page I have a Backend Query defined at the Page (top of widget tree) level. I confirm that this works.

On this page I have a Component. This Component takes a parameter which is from the Backend Query. That parameter is a document reference found in the document that I get from the Backend Query.

The Component then has a On Initialization Action to get the document from the reference passed into it from the calling page. Here when I load the page I get a null error.

During testing I changed some of the data in the document in Firestore. This caused a refresh of the page and then my Component renders without error.

So I suspect this is a timing issue. The page is calling the Component and trying to send it state but that state is coming from the Backend Query on the page.

To test this I removed the On Initialization Action from the Component and then made it so it just shows on string property from the Component Parameter I pass it. This works.

So I suspect that the On Initialization Action is not returning my document before the widget renders.

To fix this I went to the calling page and added a query for the same document I was getting in the Action and added a new parameter to the Component for this.

Seems unintuitive with the wording. I see a possible related issue reported on github:

Anyone who ends up here with similar issue, just use the Backend Query to get your data if you need it in the Component. THis can be in the Component's widget or pass it a Document as a parameter.

5 replies