Skip to content

Fix verbatim inside components#98

Merged
ganyicz merged 4 commits intomainfrom
filip/fix-verbatim
Mar 3, 2026
Merged

Fix verbatim inside components#98
ganyicz merged 4 commits intomainfrom
filip/fix-verbatim

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Mar 1, 2026

The scenario

A @verbatim block inside a Blaze component template:

<x-card>
    @verbatim /* uncompiled */ @endverbatim
</x-card>

The problem

When wrapping a Blaze component, we need to restore @php blocks so we can hoist use statements above the function definition. We used Laravel's store/restore raw blocks methods for this — but restoring raw blocks also restored the content inside @verbatim blocks. That content would then get parsed by Blade later on, defeating the purpose of @verbatim.

The solution

We already have a pattern where we store raw blocks but preserve the original content including the wrapping @verbatim/@endverbatim directives — that way when they're restored, Laravel sees the directives and ignores the content again. We just weren't applying this pattern in the Wrapper.

Extracted a shared storeRawBlock method on BladeService and added the verbatim/php regexes to LaravelRegex so both storeVerbatimBlocks and preStoreUncompiledBlocks use the same approach.

@ganyicz ganyicz marked this pull request as draft March 1, 2026 18:58
@ganyicz ganyicz changed the title Fix verbatim Fix verbatim inside components Mar 3, 2026
@ganyicz ganyicz marked this pull request as ready for review March 3, 2026 21:20
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Benchmark Results

Attempt Blade Blaze Improvement
#1 * 372.20ms 20.00ms 94.6%
#2 376.65ms 19.77ms 94.8%
#3 383.81ms 19.72ms 94.9%
#4 368.74ms 19.78ms 94.6%
#5 * 373.67ms 20.11ms 94.6%
#6 385.13ms 19.75ms 94.9%
#7 381.01ms 19.76ms 94.8%
#8 380.22ms 19.68ms 94.8%
#9 376.39ms 19.57ms 94.8%
#10 375.70ms 19.54ms 94.8%
Snapshot 378.24ms 19.66ms 94.8%
Result 378.44ms (~) 19.74ms (~) 94.8% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 49.87s total

@ganyicz ganyicz merged commit 86f18bf into main Mar 3, 2026
3 checks passed
@ganyicz ganyicz deleted the filip/fix-verbatim branch March 3, 2026 21:26
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