Skip to content

Restore buffers and section frames when a template throws - #96

Merged
harikt merged 1 commit into
6.xfrom
render-buffer-safety
Jul 23, 2026
Merged

Restore buffers and section frames when a template throws#96
harikt merged 1 commit into
6.xfrom
render-buffer-safety

Conversation

@harikt

@harikt harikt commented Jul 23, 2026

Copy link
Copy Markdown
Member

render() unwound exactly one output buffer on failure. That is enough only when the render buffer is the sole one open. beginSection() opens a second buffer and pushes a capture frame, so a template that throws mid-section leaves the render buffer orphaned and a stale frame on the stack.

Both leak into whatever renders next: output vanishes into the buffer nobody closes, and a later unmatched endSection() consumes the stale frame instead of throwing, silently capturing the wrong content under the wrong name -- which defeats the guard endSection() grew earlier in this cycle.

Record the buffer and capture depths on entry and restore both in the catch, rather than assuming a fixed depth of one. The buffering moves from View::render() to AbstractView::captureTemplate() because $capture is private to AbstractView, so the restoration has to live where the state does.

PHPUnit was already reporting these renders as risky -- "test code or tested code did not close its own output buffers".

render() unwound exactly one output buffer on failure. That is enough only when
the render buffer is the sole one open. beginSection() opens a second buffer and
pushes a capture frame, so a template that throws mid-section leaves the render
buffer orphaned and a stale frame on the stack.

Both leak into whatever renders next: output vanishes into the buffer nobody
closes, and a later unmatched endSection() consumes the stale frame instead of
throwing, silently capturing the wrong content under the wrong name -- which
defeats the guard endSection() grew earlier in this cycle.

Record the buffer and capture depths on entry and restore both in the catch,
rather than assuming a fixed depth of one. The buffering moves from
View::render() to AbstractView::captureTemplate() because $capture is private to
AbstractView, so the restoration has to live where the state does.

PHPUnit was already reporting these renders as risky -- "test code or tested
code did not close its own output buffers".
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@harikt, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c85e17cc-61b0-4a12-b311-63c3da14fc9f

📥 Commits

Reviewing files that changed from the base of the PR and between 767da4a and fc8f302.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/AbstractView.php
  • src/View.php
  • tests/RenderFailureTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch render-buffer-safety

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@harikt
harikt merged commit 9dc5593 into 6.x Jul 23, 2026
9 of 10 checks passed
@harikt
harikt deleted the render-buffer-safety branch July 23, 2026 17:41
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.

1 participant