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

Using @vite in a view that is rendered but a file response is sent back causes an exception #52784

Closed
likeadeckofcards opened this issue Sep 13, 2024 · 2 comments · Fixed by #52789

Comments

@likeadeckofcards
Copy link

Laravel Version

11.22.0

PHP Version

8.2.23

Database Driver & Version

No response

Description

If you render a view in a request for building a file such as a pdf but return the pdf file you will trigger the following exception:

Call to undefined method Symfony\\Component\\HttpFoundation\\BinaryFileResponse::header() at /project/vendor/laravel/framework/src/Illuminate/Http/Middleware/AddLinkHeadersForPreloadedAssets.php:21)

The issue is that @Vite compiles a list of urls to preload and the middleware will try to attach them to the response. It seems like the middleware should check what type of response it has before attempting to apply the header. I believe any of the ResponseFactory methods that return Symfony classes instead of Illuminate classes will also have this problem.

Steps To Reproduce

  1. Use either jetstream/breeze to setup a new project (confirm for the inertia stacks)
  2. Add a route to the web routes that renders a view containing @vite but returns a BinaryFileResponse
    return response()->file(); or return response()->file();
  3. Run npm run build (npm run hot does not compile the list of preloaded urls)
  4. Try to download the file
@likeadeckofcards
Copy link
Author

One immediate work around is to use <link href="{{Vite::asset()}}"/> in the view instead of @vite()

@timacdonald
Copy link
Member

Got a PR up to address this one. Will close this and we can follow along in the PR: #52789

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 a pull request may close this issue.

2 participants