Problem/Motivation

Branching off of a suggestion from https://www.drupal.org/project/drupal/issues/3278493 this proposal is to update development.services.yml to include Twig debugging by default.

As it currently stands, the process for enabling Twig debugging requires the user to uncomment some settings from settings.local.php then adding in the twig debugging settings to development.services.yml. This is not a very beginner-friendly process.

example.settings.local.php is filled with helpful comments and information regarding what each option does and if it should be uncommented or changed for various purposes. In contrast, development.services.yml has very little information and requires the user to add in additional information that they would not otherwise know about. Twig debugging is one of the most important features to enable when building a theme and it makes sense that it should be enabled by default in development.services.yml or at least the settings should be in the file but commented out with an explanation about what would happen if they are uncommented.

Proposed resolution

Currently development.services.yml looks like this:

parameters:
  http.response.debug_cacheability_headers: true
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

This would update the file to look like this:

parameters:
  http.response.debug_cacheability_headers: true
  # Twig debugging settings for explanation of what each option does, see:
  #  https://www.drupal.org/docs/theming-drupal/twig-in-drupal/debugging-compiled-twig-templates#options
  twig.config:
      # Html comments for Twig templates: set to true to enable
      debug: true
      # Caching the Twig templates in the Render API: 
      # set to false to disable caching so a re-render happens
      # every time a template is updated
      cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

Remaining tasks

Get DX feedback

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3278887

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rlahoda created an issue. See original summary.

vighneshh’s picture

Assigned: Unassigned » vighneshh
vighneshh’s picture

Assigned: vighneshh » Unassigned
Status: Active » Needs review
StatusFileSize
new892 bytes

Added a patch regarding this issue
Please review

vighneshh’s picture

The last one failed so added this new patch

libbna’s picture

Status: Needs review » Reviewed & tested by the community

Patch #4 applied successfully. Moving the issue to RTBC.

libbna’s picture

StatusFileSize
new77.38 KB

Adding screenshot.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 3278887-update-development-services-yml-#4.patch, failed testing. View results

rlahoda’s picture

Status: Needs work » Active
StatusFileSize
new883 bytes

I don't know if this will work because I'm not really familiar with patches and I have never tried creating a patch for Drupal core, but I noticed a typo in my original text with an extra space before the url at the top. Here's an update to the one VIGHNESH SADAGOPAL created but I did it by directly editing the original patch. I don't know if that will cause an error since there might need to be a different hash or something. If it's not correct, I would appreciate someone creating one the correct way. Thanks for all your help!

Webbeh’s picture

Status: Active » Needs work

RE #8, I would recommend not editing `.patch` files directly.

To add on to a patch, take a look at the interdiff documentation page on how to revise between versions: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... . For a complete summary of the process (including applying a patch. adding onto a patch, etc), please see: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupal

That being said, we probably should be using the GitLab fork + MR for ease-of-use and easier contributions.

Marking back to NW for the test fail in #4, which I don't think was checked (or fixed) in #8 or others.

rlahoda’s picture

@Webbeh, thanks for your input about the patch files. I went ahead and used the Gitlab process you suggested and created this MR. I have it labeled as draft because I'm new to the process here for Drupal and wasn't sure if more info is needed or anything else. https://git.drupalcode.org/project/drupal/-/merge_requests/2229

rlahoda’s picture

I'm not sure how to have the tests run on the MR so I don't know how to check/fix the fail in #4. I tried marking it as "ready" to see if that would trigger any tests in Gitlab but it doesn't appear to have done anything so I'm not sure what else to do.

tim.plunkett’s picture

The tests ran when you marked it Ready, a slight delay maybe. All good now!

Something else went wrong in that test run, but the main failure was Drupal\Tests\ComposerIntegrationTest which compares several specific files after a composer installation.
The key is to also change assets/scaffold/files/development.services.yml so that they match.

rlahoda’s picture

Thanks @tim.plunkett! I updated assets/scaffold/files/development.services.yml and pushed to the MR, how do I tell it to re-test? and were does it list the results of the tests? Maybe I'm just missing it but I don't see it listed in gitlab or on here.

rlahoda’s picture

If I'm reading the status page correctly, it looks like the latest push passed? https://dispatcher.drupalci.org/job/drupal_patches/127439/ So I'm not sure what to do next.

rlahoda’s picture

Status: Needs work » Needs review

Since it looks like the latest build passed all the tests, I'm updating the status to needs review.

Status: Needs review » Needs work

The last submitted patch, 8: 3278887-update-development-services-yml-#5.patch, failed testing. View results

spokje’s picture

Status: Needs work » Needs review

Back to NR. Failure was for patch file, and we're now using the MR. Also hidden patch #5 to make that a bit more clear.

mglaman’s picture

Status: Needs review » Needs work

Marking NW on this comment in default.services.yml

    # Twig cache:
    #
    # By default, Twig templates will be compiled and stored in the filesystem
    # to increase performance. Disabling the Twig cache will recompile the
    # templates from source each time they are used. In most cases the
    # auto_reload setting above should be enabled rather than disabling the
    # Twig cache.
    #
    # Disabling the Twig cache is not recommended in production environments.
    # @default true
    cache: true

Should we be setting cache: false over auto_reload: true? I normally do what is in the proposal. But maybe it's better to do what the docs actually recommend.

rlahoda’s picture

Status: Needs work » Needs review

Updating to Needs Review after updating and tests passed

mherchel’s picture

Assigned: Unassigned » mherchel

Assigning to myself to review.

antoniya’s picture

Issue summary: View changes

Just a few typo fixes in the IS.

I think this would be a nice improvement for DX. God knows how many times I've forgotten to exclude development.services.yml from scaffolding so that its contents got reset by drupal/core-composer-scaffold and I had to enable twig debug again.

Should the include of development.services.yml in 'container_yamls' in example.settings.local.php then be commented out by default? To prevent unexperienced users from enabling twig debug on their live sites? Or alternatively we could leave it as is but add a warning that production sites should comment out the line?

smustgrave’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Needs review » Needs work

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200

Believe this may have missed the boat for 10.0 but maybe could land in 10.1

Moving to NW so the MR can be updated for 10.1

jwilson3’s picture

The approach on this issue seems to duplicate #3272587: Enable theme debugging by default in development.services.yml which was already closed as a duplicate of #2839709. Please read on:

Per @Cottser circa 2017 in #2839709-6: Make Debugging Twig easier:

there may have been a reason to not include it. Enabling twig debug can have side effects, because of the HTML comments added. For example, #2656728: Twig split in debug mode. Enabling auto_reload for development should be safe though.

On #2839709: Make Debugging Twig easier we took another approach, to add a separate twig-debug.services.yml because:

  1. not all developers need twig debug enabled, only devs that need to find which template is rendering HTML, and override the template using one of the other suggestions.
  2. enabling it by default can break developer's local environment in several ways (causing wasted time). See #2914733: [META] twig debug can break parts of site.
  3. you cannot safely edit development.services.yml to disable twig debug, because it gets overwritten by composer scaffolding (if following best practices).

Have these questions been addressed? Can they? If not, I'm inclined to close this in favor of consolidating effort around #2839709: Make Debugging Twig easier and its waaaay more complicated successor #3278493: Make it easier for theme builders to enable Twig debugging and disable render cache.

The issue summary on this issue says:

Twig debugging is one of the most important features to enable when building a theme and it makes sense that it should be enabled by default in development.services.yml or at least the settings should be in the file but commented out with an explanation about what would happen if they are uncommented.

The approach on #2839709: Make Debugging Twig easier would have you literally uncomment a single line of code in settings.local.php to enable twig debugging, and doesnt suffer from any of the 3 drawbacks presented above. I would humbly ask for folks invested here to look there and see if there are any flaws in our thinking.

If you insist on continuing here, then at the very least I would have to insist on updating the code to add link to the Meta issue for known issues with enabling twig debug by default here: #2914733: [META] twig debug can break parts of site. Adding such a link is not going to help too much, because people will not know that Twig debugging is the root cause of many of these issues, adding to further confusion between differences on LOCAL / PROD.

jwilson3’s picture

joelpittet’s picture

Status: Needs work » Closed (duplicate)

Closing this as a duplicate of #2839709: Make Debugging Twig easier as well, thanks for outlining all the points @jwilson3 in comment #24 #3278887-24: Update development.services.yml to include twig debug by default

Cottser is of course right :D there are subtle side-effects of having this on that should be made clear. If you have very granular templates where it's rendered inside a tag, the HTML comments generated by twig_debug can break the layout, and some other subtle things around whitespace issues and HTML. Those are the side-effects we saw while adding twig to core.

Let's focus on the other issue and thanks for helping make the DX better!