Skip to content

[9.x] Fix withoutVite#43826

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
iamgergo:9.x
Aug 23, 2022
Merged

[9.x] Fix withoutVite#43826
taylorotwell merged 3 commits into
laravel:9.xfrom
iamgergo:9.x

Conversation

@iamgergo
Copy link
Copy Markdown
Contributor

This PR fixes the withoutVite method.


With the latest release some Vite methods were added, however currently they are not compatible with the withoutVite testing method.

For example in an app.blade.php:

    {{
        Vite::withEntryPoints('resources/js/app.js')
            ->useBuildDirectory('vendor/package-name/build')
            ->useHotFile(public_path('vendor/package-name/hot'))
    }}

The following error is coming up:

Error: Call to a member function useBuildDirectory() on string in ...

The methods that are returning other value type than a string for example $this must be defined. Also, the __toString is added to the anonymus class to make sure blade can render it.


I was not sure how to test it since no other tests were added to the similar fake methods.

@mabdullahsari
Copy link
Copy Markdown

I opened the PR for the very first fix.

I think that it'd be much better if an instance of $this is returned from __call. Then the __toString() can take on the responsibility for rendering nothing in the blade views.

Thoughts?

@iamgergo
Copy link
Copy Markdown
Contributor Author

Yes, I think you are right, it's a clever solution, thanks!

So, only __call, __invoke and __toString should stay, right? __call and __invoke should return with $this and __toString with ''. It is correct?

@iamgergo
Copy link
Copy Markdown
Contributor Author

Okay, so for now, I leave it as is, because I'm not sure what side effects this refactoring would have.

Thank you!

@mabdullahsari
Copy link
Copy Markdown

Yes, I think you are right, it's a clever solution, thanks!

So, only __call, __invoke and __toString should stay, right? __call and __invoke should return with $this and __toString with ''. It is correct?

Yup, that's correct.

@taylorotwell taylorotwell merged commit 698a891 into laravel:9.x Aug 23, 2022
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.

3 participants