Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a static flag (
$hasRendered
) to the Vite tag class to ensure …
…that the `{{ vite }}` tag is rendered only once per request. This change prevents the tag from being invoked multiple times during the Static Site Generation (SSG) process, thereby eliminating duplicate `<link>` and `<script>` tags in the generated `index.html`. ### Changes Made: - Introduced a `private static $hasRendered` property initialized to `false`. - Modified the `index()` method to check the `$hasRendered` flag before rendering assets. - If `$hasRendered` is `true`, the method returns an empty string, preventing further rendering. - After the first render, `$hasRendered` is set to `true` to block subsequent invocations. - Added logging to confirm that the `{{ vite }}` tag is called only once. ### Benefits: - **Performance Improvement:** Reduces redundant asset loading by eliminating duplicate asset links. - **Maintainability:** Ensures a cleaner and more efficient asset management process within the SSG. - **Debugging Ease:** Maintains logging for monitoring the invocation of the `{{ vite }}` tag. ### Testing: - Ran `npm run build` to compile assets. - Executed `php please ssg:generate` to generate the static site. - Verified `laravel.log` to ensure the `Vite` tag is called only once. - Inspected `storage/app/static/index.html` to confirm the absence of duplicated asset links. - Please use Log::info('Vite tag called with src: ' . implode(', ', $src)); to log the duplication.
- Loading branch information