Skip to content

fix: adds check for original content existence#18

Merged
gwleuverink merged 3 commits intoNativePHP:mainfrom
jsandfordhughescoop:fix-livewire-dispatch
Oct 21, 2025
Merged

fix: adds check for original content existence#18
gwleuverink merged 3 commits intoNativePHP:mainfrom
jsandfordhughescoop:fix-livewire-dispatch

Conversation

@jsandfordhughescoop
Copy link
Contributor

I was unable to build or run the application because the $handled->response object did not contain the original property.

I implemented a local fix that resolved the issue at the time. However, after several subsequent builds and runs, I haven’t been able to reproduce the problem — all $handled->response objects now correctly include the original property.

I’m not sure what initially caused the missing property, but this change ensures that similar build or runtime failures won’t occur in the future.

@gwleuverink
Copy link
Collaborator

This is great I was just looking into a bug report about this 👌

I have to double check but I think we can do away with the early return. If originalContent was null in the first place it's probably okay continue execution

@jsandfordhughescoop
Copy link
Contributor Author

This is great I was just looking into a bug report about this 👌

I have to double check but I think we can do away with the early return. If originalContent was null in the first place it's probably okay continue execution

The problem, was that it wasn't null but missing altogether. We could do away with the early return but will need to guard against dynamic property creation at the end by doing something like:

if (property_exists($handled->response, 'original')) {
    $handled->response->original = $originalContent;
}

Keen to hear thoughts

@gwleuverink
Copy link
Collaborator

Perfect yeah that feels right.

I'm not sure why that original property is usually present but sometimes not. And I'm weary that an early return might cause some hard to debug issues down the line. So your latest suggestion is great 👌

Would you be willing to add that? I'll test it and make sure it's released tomorrow

@jsandfordhughescoop
Copy link
Contributor Author

if (property_exists($handled->response, 'original')) {
    $handled->response->original = $originalContent;
}

@gwleuverink - No problem, all done 👍

@gwleuverink
Copy link
Collaborator

Hey @jsandfordhughescoop I've just pulled in your PR. Running into a static analysis issue.

https://github.com/NativePHP/desktop/actions/runs/18675299098/job/53248255203?pr=18

It says that property_exists always returns true, and inspecting the Illuminate\Http\Response I can see indeed it should always exist.

The problem, was that it wasn't null but missing altogether.

Do you have any idea why it could be missing? Do you have the original error message or how to reproduce?

@gwleuverink
Copy link
Collaborator

Hmm I reproduced it. In my case it is thrown on a Symfony\Component\HttpFoundation\BinaryFileResponse, which doesn't have this property.

Weird eh? I suppose Laravel must be dispatching this event even other response types so their phpdoc type in the event is a bit misleading.

I'll just ignore the line in phpstan, your solution works as it should 👍🏻

@gwleuverink
Copy link
Collaborator

  • Pint action can't run on external repo. Ran it locally - all is green

@gwleuverink gwleuverink merged commit 4c5793c into NativePHP:main Oct 21, 2025
28 of 29 checks passed
@gwleuverink
Copy link
Collaborator

Merged! Thanks @jsandfordhughescoop 🙏🏻

I'll be looking into some other issues & do a combined release later today

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.

2 participants