mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
simplify and add docs warning
This commit is contained in:
@@ -222,7 +222,7 @@ public function panel(Panel $panel): Panel
|
||||
|
||||
SPA prefetching enhances the user experience by automatically prefetching pages when users hover over links, making navigation feel even more responsive. This feature utilizes [Livewire's `wire:navigate.hover` functionality](https://livewire.laravel.com/docs/navigate#prefetching-links).
|
||||
|
||||
To enable SPA mode with prefetching, you can pass the `prefetch` parameter to the `spa()` method:
|
||||
To enable SPA mode with prefetching, you can pass the `hasPrefetching: true` parameter to the `spa()` method:
|
||||
|
||||
```php
|
||||
use Filament\Panel;
|
||||
@@ -231,7 +231,7 @@ public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->spa(prefetch: true);
|
||||
->spa(hasPrefetching: true);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -241,6 +241,10 @@ When prefetching is enabled, all links within your panel will automatically incl
|
||||
Prefetching only works when SPA mode is enabled. If you disable SPA mode, prefetching will also be disabled automatically.
|
||||
</Aside>
|
||||
|
||||
<Aside variant="warning">
|
||||
Prefetching heavy pages can lead to increased bandwidth usage and server load, especially if users hover over many links in quick succession. Use this feature judiciously, particularly if your app has pages with large amounts of data or complex queries.
|
||||
</Aside>
|
||||
|
||||
## Unsaved changes alerts
|
||||
|
||||
You may alert users if they attempt to navigate away from a page without saving their changes. This is applied on [Create](resources/creating-records) and [Edit](resources/editing-records) pages of a resource, as well as any open action modals. To enable this feature, you can use the `unsavedChangesAlerts()` method:
|
||||
|
||||
@@ -15,10 +15,10 @@ trait HasSpaMode
|
||||
*/
|
||||
protected array | Closure $spaModeUrlExceptions = [];
|
||||
|
||||
public function spa(bool | Closure $condition = true, bool | Closure $prefetch = false): static
|
||||
public function spa(bool | Closure $condition = true, bool | Closure $hasPrefetching = false): static
|
||||
{
|
||||
$this->hasSpaMode = $condition;
|
||||
$this->hasSpaPrefetching = $prefetch;
|
||||
$this->hasSpaPrefetching = $hasPrefetching;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static bool hasSpaMode(?string $url = null)
|
||||
* @method static bool hasSpaPrefetching(?string $url = null)
|
||||
* @method static bool hasSpaPrefetching()
|
||||
* @method static Htmlable renderHook(string $name, string | array<string> | null $scopes = null)
|
||||
*
|
||||
* @see ViewManager
|
||||
@@ -31,10 +31,10 @@ class FilamentView extends Facade
|
||||
});
|
||||
}
|
||||
|
||||
public static function spa(bool $condition = true, bool $prefetch = false): void
|
||||
public static function spa(bool $condition = true, bool $hasPrefetching = false): void
|
||||
{
|
||||
static::resolved(function (ViewManager $viewManager) use ($condition, $prefetch): void {
|
||||
$viewManager->spa($condition, $prefetch);
|
||||
static::resolved(function (ViewManager $viewManager) use ($condition, $hasPrefetching): void {
|
||||
$viewManager->spa($condition, $hasPrefetching);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -78,10 +78,10 @@ class ViewManager
|
||||
return new HtmlString(implode('', $hooks));
|
||||
}
|
||||
|
||||
public function spa(bool $condition = true, bool $prefetch = false): void
|
||||
public function spa(bool $condition = true, bool $hasPrefetching = false): void
|
||||
{
|
||||
$this->hasSpaMode = $condition;
|
||||
$this->hasSpaPrefetching = $prefetch;
|
||||
$this->hasSpaPrefetching = $hasPrefetching;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,8 +112,8 @@ class ViewManager
|
||||
return is_app_url($url);
|
||||
}
|
||||
|
||||
public function hasSpaPrefetching(?string $url = null): bool
|
||||
public function hasSpaPrefetching(): bool
|
||||
{
|
||||
return $this->hasSpaMode($url) && $this->hasSpaPrefetching;
|
||||
return $this->hasSpaPrefetching;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ if (! function_exists('Filament\Support\generate_href_html')) {
|
||||
} elseif ($shouldOpenInSpaMode ?? (FilamentView::hasSpaMode($url))) {
|
||||
$html .= ' wire:navigate';
|
||||
|
||||
if (FilamentView::hasSpaPrefetching($url)) {
|
||||
if (FilamentView::hasSpaPrefetching()) {
|
||||
$html .= '.hover';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,6 @@ test('SPA prefetching can be toggled', function (): void {
|
||||
expect(FilamentView::hasSpaPrefetching())->toBeFalse();
|
||||
});
|
||||
|
||||
test('SPA prefetching requires SPA mode to be enabled', function (): void {
|
||||
FilamentView::spa(false, true);
|
||||
expect(FilamentView::hasSpaPrefetching())->toBeFalse();
|
||||
|
||||
FilamentView::spa(true, true);
|
||||
expect(FilamentView::hasSpaPrefetching())->toBeTrue();
|
||||
});
|
||||
|
||||
test('`href` HTML can be generated with `wire:navigate` based on SPA mode', function (): void {
|
||||
FilamentView::spa();
|
||||
expect(generate_href_html('http://localhost/page'))
|
||||
@@ -95,14 +87,6 @@ test('SPA URL exceptions work correctly', function (): void {
|
||||
expect(FilamentView::hasSpaMode('http://localhost/dashboard'))->toBeTrue();
|
||||
});
|
||||
|
||||
test('SPA prefetching respects URL exceptions', function (): void {
|
||||
FilamentView::spa(true, true);
|
||||
FilamentView::spaUrlExceptions(['*/admin/*']);
|
||||
|
||||
expect(FilamentView::hasSpaPrefetching('http://localhost/admin/users'))->toBeFalse();
|
||||
expect(FilamentView::hasSpaPrefetching('http://localhost/dashboard'))->toBeTrue();
|
||||
});
|
||||
|
||||
test('`href` HTML respects SPA URL exceptions for prefetching', function (): void {
|
||||
FilamentView::spa(true, true);
|
||||
FilamentView::spaUrlExceptions(['*/admin/*']);
|
||||
|
||||
Reference in New Issue
Block a user