Found a bug or some undocumented edge case #8257
Unanswered
Sebbito
asked this question in
Help/Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
About this
This will be a longer description since I can't correctly classify where this bug stems from yet I do know how to fix it.
Project dependencies:
What i wanted to happen
I wanted a parent component to call the
getCosts()
Method of an API Class and pass the result to a child component that uses this data to generate HTML via av-for
loop for each cost returned bygetCosts
.What actually happend
The program always fetched the data but in Chrome it only sometimes filled the child component.
Depending on the environment the results also differed.
For Chrome:
In develop and preview mode (
npm run dev
ornpm run preview
) the site was always generated correctly.The compiled version of the project had this random behaviour.
For Firefox:
Firefox never generated the site parts.
I didn't test other Browsers.
Code
I will only post the relevant snippets here. For the parts that were never declared anywhere: just assume that they're there and do what they say.
This was the Parent component that called the API and also used the child component:
The OptionalCosts component used
costs
as prop like this:This was a cutout from the API Module that held the used API Class and Interface definition:
Fix
The really relevant part is the function in the API that I commented. It seems like using the result of the API call like that will not allow the Component to update correctly once the data has been received.
To fix this i made the
getCosts
function take the array from the parent component and fill it with data instead:Makes for a function call like this in the parent component:
This works as intended.
Why?
Now why does it only behave as expected when I set the values in the callback of the
this._get()
method? I know it makes more sense but shouldn't it work regardless?I don't really see the difference between the two implementation and why one behaves very different from the other especially since it says nowhere not to do it like I've done it in the first draft.
Does it have to do with promises and the execution time of the callback?
Could it be that the
costs.push
is only executed after evaluating the promise has been resolved and in the first draft i get no data since the promise still didn't resolve by then?Beta Was this translation helpful? Give feedback.
All reactions