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
```vue
test
test2
Content loading below:
I am indeed loading, hold on...Done loading. Even though on a new visit I should reload.
```
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
```php
Route::get('/test', function () {
return inertia('Test', [
'data' => Inertia::lazy(function() {
sleep(3); // To simulate api call (exaggerated)
return;
})
]);
});
Route::get('/test2', function () {
return inertia('Test', [
'data' => Inertia::lazy(function() {
sleep(3);
return;
})
]);
});
```
Visit /test
Click the test2 link on the page and observe the console and/or page
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
```vueOptionally you could create 2 components (Test1 and Test2), but it has the same effect.
Create 2 routes to our web.php:
Click to expand
```php Route::get('/test', function () { return inertia('Test', [ 'data' => Inertia::lazy(function() { sleep(3); // To simulate api call (exaggerated) return; }) ]); }); Route::get('/test2', function () { return inertia('Test', [ 'data' => Inertia::lazy(function() { sleep(3); return; }) ]); }); ```Visit
/test
Click the
test2
link on the page and observe the console and/or page