Skip to content

[4.x] Fix BaseAuthorze and BaseRenderless not triggered using event - #10384

Merged
calebporzio merged 3 commits into
livewire:mainfrom
ghabriel25:fix/support-events
Jul 7, 2026
Merged

[4.x] Fix BaseAuthorze and BaseRenderless not triggered using event#10384
calebporzio merged 3 commits into
livewire:mainfrom
ghabriel25:fix/support-events

Conversation

@ghabriel25

@ghabriel25 ghabriel25 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Scenario

When user wants to contribute to this repo and preparing some browser / unit test related to #[Authorize] and #[Renderless] attribute, they might be not aware that using #[BaseAuthorize] or #[BaseRenderless] wont be triggered if action called as event listener.

I'm aware that all Base* attribute should be strictly for internal use as stated here #10346 (comment).

Problem

Inside SupportEvents::call, both renderless and authorize attribute checked using is_subclass_of

$this->component->getAttributes()
    ->filter(fn ($i) => is_subclass_of($i, BaseAuthorize::class) // here
    ->filter(fn ($i) => $i->getName() === $method)
    ->filter(fn ($i) => $i->getLevel() === AttributeLevel::METHOD)
    ->each(fn ($i) => $i->call($params));

I think the intent here is a good one that prevent using Base** attribute as public API. But, this will cause some unsual issue when running tests. Therefore, I still think this need to be fixed.

Solution

Change is_subclass_of to instanceof

$this->component->getAttributes()
    ->filter(fn ($i) => $i instanceof BaseAuthorize)
    ->filter(fn ($i) => $i->getName() === $method)
    ->filter(fn ($i) => $i->getLevel() === AttributeLevel::METHOD)
    ->each(fn ($i) => $i->call($params));

I have added regression test for both authorize unit test and renderless browser test.

Files Changed

  • src/Features/SupportEvents/SupportEvents.php
  • src/Features/SupportAuthorization/UnitTest.php
  • src/Features/SupportRenderless/BrowserTest.php

Fix: #10383

ghabriel25 and others added 3 commits July 4, 2026 16:38
The existing test dispatches the event as an authorized user and asserts
Ok, which also passes without the fix (the outcome is the same whether
the authorize check runs or is skipped). This adds a test with an
unauthorized user asserting Forbidden, which fails on main and passes
with the instanceof fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@calebporzio calebporzio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @ghabriel25 — thanks for this one, and for the clear writeup on the issue. The fix is right: the direct-call path runs these attributes for anything matching at the method level, so the event path filtering with is_subclass_of (which excludes the base class itself) was just an inconsistency. instanceof is the correct check.

Here's what I ran to verify:

  • Renderless browser test: fails on main's SupportEvents.php, passes with your fix. Solid regression test.
  • Authorize unit test: I noticed your new test passes on main too — it dispatches as an authorized user and asserts Ok, which is the same outcome whether the authorize check runs or gets skipped, so it wasn't actually guarding the fix. I pushed a small commit to your branch adding a variant that dispatches as an unauthorized user and asserts Forbidden — verified it fails on main and passes here. Hope you don't mind the direct push!
  • Full unit suite: green on this branch.

Happy with this — good to merge from my side.

@ghabriel25

Copy link
Copy Markdown
Contributor Author

@calebporzio Thanks for the review.

@calebporzio
calebporzio merged commit 64fdee5 into livewire:main Jul 7, 2026
31 of 32 checks passed
@ghabriel25
ghabriel25 deleted the fix/support-events branch July 7, 2026 11:13
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.

BaseRenderless and BaseAuthorize attribute doesnt work inside browser test when action trigerred as event listener

2 participants