Prevent rendering of render cache debugging comments

Created on 9 July 2025, 3 months ago

Problem/Motivation

When render cache debugging β†’ is enabled (services.yml, parameters > render.config > debug: true), the output will contain render cache debugging comments. This prevents the parsing of the response, especially if the return type is JSON.

The render cache debugging comments don't seem to appear if the response is a JsonResponse straight from a controller. I have not looked into where rest_views and a straight up controller returning JsonResponse differ. I also could not find where or how to selectively disable render cache debugging when on a rest_views route.

While render cache debugging is never enabled on deployed code (i.e. this never actually happens on production), it's inconvenient during development where all debugging options are turned on.

Steps to reproduce

1. Enable render cache debugging β†’ and rebuild cache.
2. Render a textbox with an autocomplete (e.g. render a block on the page with a textfield render element that has the #autocomplete_route_name property whose value is a route name).
3. Create a controller on a route, have it return a JsonResponse of an array whose items are arrays containing a label and value property.
4. Create a rest_views display returning the same thing as Step 2.
5. Use the route of the controller in Step 3 as the autocomplete route.
6. Use the route of the view in Step 4 as the autocomplete route.

Expected:
- Steps 5 and 6 produce identical working autocomplete.

Actual:
- Step 6 will have a working autocomplete.
- Step 7 will have a broken autocomplete because the JSON from the view has HTML comments.

Proposed resolution

- Make rest_views displays not render debug comments in the output.

Remaining tasks

- Investigate.
- Fix.
- Test.
- Merge fix.

User interface changes

- None.

API changes

- rest_views displays will render valid JSON regardless of the state of render cache debugging.

Data model changes

- rest_views displays will render valid JSON regardless of the state of render cache debugging.

πŸ› Bug report
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fskreuz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024