Skip to content

Fix: AfterChunk event raised after sheet disconnect#4385

Open
zigzagdev wants to merge 12 commits into
SpartnerNL:4.xfrom
zigzagdev:fix/after-chunk-method-timing
Open

Fix: AfterChunk event raised after sheet disconnect#4385
zigzagdev wants to merge 12 commits into
SpartnerNL:4.xfrom
zigzagdev:fix/after-chunk-method-timing

Conversation

@zigzagdev

Copy link
Copy Markdown

1️⃣Why should it be added? What are the benefits of this change?

AfterChunk was fired after Sheet::disconnect() in ReadChunk::handle().
disconnect() calls unset($this->worksheet), so any event handler that accesses $event->getSheet()->getDelegate() would encounter an undefined property and receive null instead of the expected Worksheet instance.
Moving raise(AfterChunk) before disconnect() ensures the worksheet is still accessible inside event handlers, which is the naturally expected behavior.

2️⃣Does it contain multiple, unrelated changes?

No.
This PR contains a single focused fix: reordering raise(AfterChunk) and disconnect() in ReadChunk::handle().

3️⃣Does it include tests, if possible?

Yes.
test_after_chunk_event_sheet_delegate_is_accessible has been added to WithEventsTest, asserting that $event->getSheet()->getDelegate() returns a Worksheet instance within an AfterChunk handler.

4️⃣Any drawbacks? Possible breaking changes?

No breaking changes.
The fix only corrects the order of two operations. Event handlers that do not access getDelegate() are unaffected.

5️⃣Tasks

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

Test Results

screen capture 2026-06-06 0 21 49

ZakAmirou and others added 12 commits October 22, 2025 17:45
… table (SpartnerNL#4325)

Co-authored-by: Zakaria Amirou <zakaria.amirou@cynapsis.de>
…nsistency (SpartnerNL#4330)

* Fix: correct TSV constant value and update parameter name in store method

* Fix: update TSV constant value, add file path parameter to WriterFactory, and implement TSV file detection logic

* style: format code in WriterFactory for consistency
* feat: Update composer.json for Laravel 13 support

* update CI

* try to run on testbench 10

* exclude php 8.2 on L13

* testbench 11

* testbench 11 in composer.json

* scout 11 in composer.json

* scout 11 in ci

* wip

* try W
* suppress error from mkdir

* test

---------

Co-authored-by: lukekuzmish <lukekuzmish@loopreturns.com>
@patrickbrouwers

Copy link
Copy Markdown
Member

can you retarget this to 4.x

@patrickbrouwers patrickbrouwers changed the base branch from 3.1 to 4.x July 9, 2026 08:02
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.