Skip to content

Recompile components compiled inside with_new_cache - #2735

Merged
joelhawksley merged 2 commits into
ViewComponent:mainfrom
anthony0030:fix-annotations-test-order
Oct 22, 2026
Merged

joelhawksley merged 2 commits into
ViewComponent:mainfrom
anthony0030:fix-annotations-test-order

Conversation

@anthony0030

Copy link
Copy Markdown
Contributor

What are you trying to accomplish?

IntegrationTest#test_rendering_component_with_template_annotations_enabled fails for some test orders. It failed the Rails 8.1 job on #2734 with seed 6880, and the same seed fails on main (18619ae):

Expected "<!-- BEGIN app/views/integration_examples/index.html.erb\n--><span><div>\n  Foo\n  bar\n</div>\n<!-- END app/components/erb_component.html.erb --></span>\n..." to include "BEGIN app/components/erb_component.html.erb".

To reproduce: bundle exec rake test TESTOPTS="--seed=6880".

What approach did you choose and why?

InlineTemplateTest's "file-based templates compile without segfault when coverage is running" recompiles ErbComponent inside with_new_cache while Coverage is running. Under coverage, Template::File#compiled_source strips the BEGIN annotation line on purpose. When the block ends, with_new_cache restores the previous cache, which still lists ErbComponent as compiled, so the stripped methods stay on the class. If the integration test runs later, it renders those methods and the BEGIN annotation is missing. The "annotations disabled" variant leaves ErbComponent compiled without annotations in the same way.

with_new_cache now removes the components compiled inside the block from the restored cache, so they compile again under the normal settings the next time they render. This fixes the helper rather than the two tests, because any test that compiles a component inside with_new_cache under temporary settings can leak them the same way.

Anything you want to highlight for special attention from reviewers?

The only cost is that those components compile once more after the block. Locally the full suite passes with seed 6880 and seeds 42, 1234 and 777 on Rails 8.1.2 and 8.1.4, and standardrb is clean. With seeds 1, 9999 and 31337, ViewComponentSystemTest#test_layout_is_not_nested timed out in headless Chrome on my machine. Seed 1 times out the same way on main without this change, so it looks local rather than related.

This came up on #2734, whose Rails 8.1 job failed with seed 6880.

🤖 Generated with Claude Code

anthony0030 and others added 2 commits October 22, 2026 16:48
Components compiled in the block keep the settings they were compiled
under, such as coverage stripping the BEGIN annotation, but the restored
cache still listed them as compiled. The template annotations integration
test then failed whenever it ran after the coverage compile tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@joelhawksley
joelhawksley merged commit b7828ab into ViewComponent:main Oct 22, 2026
19 checks passed
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.

2 participants