Blade @php block inside <statamic:nocache> is left as an unresolved @__raw_block_N__@ placeholder
维护者通常 1 天内回复
评估
调研方向
Start with src/View/Blade/Concerns/CompilesNocache.php and trace how the nocache element's inner content is extracted and written during Blade precompilation. Compare the generated _nocache*.blade.php view with the main compiled view for the reproduced multiline @php example. Done means the extracted view preserves and executes the block so the example renders
ok; a linked open pull request may already be addressing this.由索引模型根据 Issue 内容生成。
描述
Bug description
A multiline Blade @php ... @endphp block placed directly inside <statamic:nocache> is not restored correctly in the temporary Blade view generated by Statamic.
The PHP block is replaced with an unresolved @__raw_block_N__@ placeholder. As a result, the PHP code is never executed and variables initialized by that block are undefined when the nocache region is rendered.
This may be either a bug or an undocumented limitation of the Blade nocache compiler. The documentation shows Blade directives inside <statamic:nocache> and does not mention that multiline @php blocks are unsupported.
How to reproduce
Create a Blade view containing:
<statamic:nocache>
@php
$value = 'ok';
@endphp
<div>{{ $value }}</div>
</statamic:nocache>
Enable Statamic static caching and render the page.
The problem can also be observed before the HTTP nocache replacement occurs by compiling the view with the application's Blade compiler and inspecting the generated _nocache*.blade.php view.
The generated view contains something similar to:
@__raw_block_0__@
<div>{{ $value }}</div>
When the nocache region is rendered, Laravel then reports:
Undefined variable $value
Expected behavior
The @php ... @endphp block should be preserved in the extracted nocache view, compiled, and executed when the dynamic region is rendered.
The example above should render:
<div>ok</div>
Actual behavior
The multiline PHP block is replaced by a literal @__raw_block_N__@ token in the generated nocache view.
Because the original PHP code is not restored, $value is never initialized and rendering fails with an undefined-variable exception.
Logs
Environment
- Statamic CMS: 6.31.0
- Laravel Framework: 12.69.1
- PHP: 8.4.13
- stillat/blade-parser: 2.1.0
- Static caching strategy: half
- Laravel views cached
Installation
Fresh statamic/statamic site via CLI
Additional details
My current understanding of the compilation flow is:
- Laravel temporarily replaces multiline @php ... @endphp blocks with raw-block placeholders during BladeCompiler::compileString().
- Statamic's Blade precompiler processes statamic:nocache while the placeholder is still present.
- CompilesNocache::compileNocache() extracts the element's inner content and writes it to a separate nocache Blade view.
- Laravel later restores raw blocks in the main compiled view, but it can no longer restore the placeholder that was moved to the separate nocache file.
The likely integration point is:
src/View/Blade/Concerns/CompilesNocache.php
In particular, the extraction and writing of $component->innerDocumentContent during Blade precompilation may occur before Laravel restores its raw blocks.
This is only an analysis of the observed behavior; I am not certain what the preferred fix should be.
Some related observations:
- An inline expression such as @php($value = 'ok') remains intact in the compilation I tested.
- Adding select does not fix the problem. The affected variable is created locally inside the nocache region.
- Extracting the dynamic region to a partial works correctly:
@nocache('partials.dynamic-region')
The multiline @php block can then live inside partials/dynamic-region.blade.php and is compiled normally.
- 主要语言
- PHP
- 星标
- 4.9k
- 派生
- 647
- 平均合并
- 1 天 45 分钟
- 30 天内合并 PR
- 221
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
statamic/cms 的其他 Issue
-
forms ui
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
accessibility
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
antlers
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
Nav: link to the site root with an anchor (/#section) gets is_parent on every page可能已有人在做 @duncanmcclean 今天认领。 未关闭navigations
难度 2/5 1-3 小时 新手友好度 35/100
维护者通常 1 天内回复
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use it可能已有人在做 @duncanmcclean 今天认领。 未关闭forms
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
sync-en
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
taskforcesh/bullmq#5238 ·
维护者通常 1 天内回复
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects it可能已有人在做 @bfs2021 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
Automattic/jetpack#55517 ·
维护者通常 1 天内回复