-
-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to prevent redundant data fetching when the page is fully loaded? #998
Comments
I think a more suitable would be to use action and state. Available from context |
Thanks for the kind words too. |
@slegrand45 do you need a fetch at pre-render (in the back end)? I think you could check |
Thank you very much for your responses. @oderwat, I'll definitely examine the go-nats-app example. Ideally, I'd like to set the value of a component field within the OnPreRender() method and then be able to retrieve that value on the client-side within the OnMount() or OnNav() methods. Something like this: type hello struct {
app.Compo
Name string
}
func (h *hello) OnPreRender(ctx app.Context) {
h.Name = "myvalue"
}
func (h *hello) OnMount(ctx app.Context) {
// display "myvalue" even when running on the client
// so no need to call the server again to retrieve that value
app.Log(h.Name)
} I may be wrong but that seems impossible at this time. |
@slegrand45 What you do in PreRender is not accessible by the frontend. It will be replaced with the actual loader if the JS is run. PreRender is meant for SEO only. Ways to share variables between backend and frontend (after compilation) which I am aware of are:
There is nothing else how you could get data to the frontend after compilation afaik. Using "Env" or "RawHeaders" will also only work on installation/updating of the App in the Hosts Browser Engine (not on reloads). This means: You can't change this in the backend without bumping Just as a reminder: This is a framework for PWAs and therefore will use caching of all the data in such a way, that it works without a network connection after it got installed. So any kind of "backend" access is basically an "add on" which needs to be maintained by the developer of the application itself. @maxence-charriere I hope I am right with those claims. Please confirm and correct me when needed. |
Hi,
First of all, congratulations for this amazing package. It's really an impressive work. go-app certainly deserves to be better known.
I'm currently developing an application where I need to fetch data from the backend server. I'm using [Connect] (https://connectrpc.com/) for this purpose.
According to my understanding, the data fetching code should reside within either the OnMount() or OnNav() methods of the components. However, I've observed that when the page fully loads, the fetching code gets called twice: once during what I presume to be pre-rendering, and again when OnMount()/OnNav() is triggered on the client-side.
Is there a way to prevent this redundant data fetching? This issue, of course, doesn't occur after the initial application load as pre-rendering is no longer a factor.
Thank you for your help.
The text was updated successfully, but these errors were encountered: