feat: allow to highlight slots and components for debugging (#942)

This commit is contained in:
Juro Oravec 2025-02-02 10:14:47 +01:00 committed by GitHub
parent da54d97343
commit de32d449d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 306 additions and 49 deletions

View file

@ -34,7 +34,7 @@ from django.test.signals import template_rendered
from django.utils.html import conditional_escape
from django.views import View
from django_components.app_settings import ContextBehavior
from django_components.app_settings import ContextBehavior, app_settings
from django_components.component_media import ComponentMediaInput, ComponentMediaMeta
from django_components.component_registry import ComponentRegistry
from django_components.component_registry import registry as registry_
@ -69,6 +69,7 @@ from django_components.slots import (
resolve_fills,
)
from django_components.template import cached_template
from django_components.util.component_highlight import apply_component_highlight
from django_components.util.context import snapshot_context
from django_components.util.django_monkeypatch import is_template_cls_patched
from django_components.util.exception import component_error_message
@ -1153,6 +1154,9 @@ class Component(
del component_context_cache[render_id] # type: ignore[arg-type]
unregister_provide_reference(render_id) # type: ignore[arg-type]
if app_settings.DEBUG_HIGHLIGHT_COMPONENTS:
html = apply_component_highlight("component", html, f"{self.name} ({render_id})")
return html
post_render_callbacks[render_id] = on_component_rendered