Skip to content

Commit d315745

Browse files
authored
Add ability to flush state on Vite helper (#55228)
1 parent 8dfc3d4 commit d315745

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Illuminate/Foundation/Vite.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,4 +1023,14 @@ public function toHtml()
10231023
{
10241024
return $this->__invoke($this->entryPoints)->toHtml();
10251025
}
1026+
1027+
/**
1028+
* Flush state.
1029+
*
1030+
* @return void
1031+
*/
1032+
public function flush()
1033+
{
1034+
$this->preloadedAssets = [];
1035+
}
10261036
}

tests/Foundation/FoundationViteTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,18 @@ public function testItCanConfigureThePrefetchTriggerEvent()
16931693
$this->cleanViteManifest($buildDir);
16941694
}
16951695

1696+
public function testItCanFlushState()
1697+
{
1698+
$this->makeViteManifest();
1699+
1700+
app(Vite::class)('resources/js/app.js');
1701+
app()->forgetScopedInstances();
1702+
$this->assertCount(1, app(Vite::class)->preloadedAssets());
1703+
1704+
app(Vite::class)->flush();
1705+
$this->assertCount(0, app(Vite::class)->preloadedAssets());
1706+
}
1707+
16961708
protected function cleanViteManifest($path = 'build')
16971709
{
16981710
if (file_exists(public_path("{$path}/manifest.json"))) {

0 commit comments

Comments
 (0)