You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Will not work because the onFinish in this reload is also executed when the page itself has finished loading. This will set the value of loading to false when the page is shown. Rendering the feedback useless.
This happens only when visiting a page though Inertia and router.reload'ing on that page, not when reloading a page with the browser (initial visit)
The timing looks something like this:
Event
loading
Click link to page
-
Page component mounted
true
onMounted is called, router.reload begins.
true
onFinish of the page visit is called.
false
router.reload is still processing
false
onFinish is called again after reload finished
false
This happens so fast that the user doesn't ever see the loading feedback for the router.reload. My suspicion is that the onFinish in any inertia router visit is listening to the same event. Meaning that this reload is called twice because of the page finishing loading and the reload finishing loading.
Here's a console output of this series of events with timestamps (dayjs format: HH:mm:ss.SSS):
We do this to make the page appear faster and lazy load the data later (due to external api calls from the back end). It could be possible that this is not the way to do it. If so, I would like to know how this should be done.
Steps to reproduce:
Create page component, with the following code:
Click to expand
<scriptsetuplang="ts">import { Link, router } from'@inertiajs/vue3'import { onMounted, ref } from'vue'const loading =ref(true)onMounted(() => {router.reload({ only: ['data'],onStart: () => {loading.value=trueconsole.log(`onStart called. loading.value: ${loading.value}`) },onFinish: () => {loading.value=falseconsole.log(`onFinish called. loading.value: ${loading.value}`) } })})</script>
<template>
<div>
<Linkhref="/test">
test
</Link>
<Linkhref="/test2">
test2
</Link>
Content loading below:
<hr>
<div>
<spanv-if="loading">I am indeed loading, hold on...</span>
<spanv-else>Done loading. Even though on a new visit I should reload.</span>
</div>
</div>
</template>
Optionally you could create 2 components (Test1 and Test2), but it has the same effect.
Create 2 routes to our web.php:
Click to expand
Route::get('/test', function () {
returninertia('Test', [
'data' => Inertia::lazy(function() {
sleep(3); // To simulate api call (exaggerated)return;
})
]);
});
Route::get('/test2', function () {
returninertia('Test', [
'data' => Inertia::lazy(function() {
sleep(3);
return;
})
]);
});
Visit /test
Click the test2 link on the page and observe the console and/or page
The text was updated successfully, but these errors were encountered:
Version:
@inertiajs/vue3
version: 1.0.14Describe the problem:
Having code like this on a page:
Will not work because the
onFinish
in this reload is also executed when the page itself has finished loading. This will set the value ofloading
tofalse
when the page is shown. Rendering the feedback useless.This happens only when visiting a page though Inertia and
router.reload
'ing on that page, not when reloading a page with the browser (initial visit)The timing looks something like this:
true
onMounted
is called, router.reload begins.true
onFinish
of the page visit is called.false
false
onFinish
is called again after reload finishedfalse
This happens so fast that the user doesn't ever see the loading feedback for the router.reload. My suspicion is that the
onFinish
in any inertiarouter
visit is listening to the same event. Meaning that this reload is called twice because of the page finishing loading and the reload finishing loading.Here's a console output of this series of events with timestamps (dayjs format: HH:mm:ss.SSS):
We do this to make the page appear faster and lazy load the data later (due to external api calls from the back end). It could be possible that this is not the way to do it. If so, I would like to know how this should be done.
Steps to reproduce:
Create page component, with the following code:
Click to expand
Optionally you could create 2 components (Test1 and Test2), but it has the same effect.
Create 2 routes to our web.php:
Click to expand
Visit
/test
Click the
test2
link on the page and observe the console and/or pageThe text was updated successfully, but these errors were encountered: