Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix setting custom ASSET_URLs and support cache busting without integrity check #1427

Merged

Conversation

mmachatschek
Copy link
Contributor

@mmachatschek mmachatschek commented Apr 24, 2024

Fixes #1425
Fixes #1426

There were already tries to integrate Vite with telescope which have been postponed because of the linked issues and other concerns. I think this PR now solves all of these issues.

@timacdonald I would love to hear your opinion as well as you were involved in a lot of these discussions as well:

also related:

Screenshots:

Running vite dev mode renders the "none" vite url
image

Setting a custom ASSET_URL works:

image

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

import { resolve } from "node:path";
import { readFileSync, writeFileSync } from "node:fs";

function manifestQueryParam() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This vite plugin aims to provide the same functionality of cache busting (with md5 hash route parameter) as laravel mix did instead of using integrity checks on the tags and passing the integrity key in the manifest.

Comment on lines +22 to +25
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" />
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" data-scheme="light" />
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" />
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" data-scheme="dark" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Vite Helper doesn't support rendering css files with parameters. they need to end with .css/.less etc. thats why we need to handcraft this.

https://github.com/laravel/framework/blob/c2668c7deeabb59c96181b8a6e2bb2c08b9425eb/src/Illuminate/Foundation/Vite.php#L595-598

use Illuminate\Support\Facades\Vite;
use Illuminate\Foundation\Vite as ViteFoundation;
$nonExistentFileName = public_path('/vendor/horizon/nonExistentFile');
$previousHotFile = Vite::hotFile();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We save the previously detected hotfile of the user so we can reset the hotfile at the end of the blade template and "restore" the previous state.

@mmachatschek mmachatschek marked this pull request as ready for review April 24, 2024 21:41
@taylorotwell taylorotwell merged commit 1b5a027 into laravel:5.x Apr 29, 2024
12 checks passed
@mmachatschek mmachatschek deleted the fix_integrity_asset_url_issue branch April 29, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subresource Integrity failures when using ASSET_URL The horizon dashboard does not have stylesheet loaded
2 participants