mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
fix: KeyError on component_context_cache when slot rendered outside (#1210)
This commit is contained in:
parent
6ff2d78a2f
commit
046569e16d
3 changed files with 71 additions and 7 deletions
|
@ -474,3 +474,54 @@ class TestSlot:
|
|||
match=re.escape("Fill 'first' received content both through 'body' kwarg and '{% fill %}' body."),
|
||||
):
|
||||
template.render(Context({"my_slot": my_slot}))
|
||||
|
||||
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
|
||||
def test_slot_call_outside_render_context(self, components_settings):
|
||||
from django_components import register, Component
|
||||
|
||||
seen_slots = []
|
||||
|
||||
@register("MyTopLevelComponent")
|
||||
class MyTopLevelComponent(Component):
|
||||
template = """
|
||||
{% for thing in words %}
|
||||
{% component "MyComponentBeingLooped" / %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {
|
||||
"words": ["apple", "car", "russia"],
|
||||
}
|
||||
|
||||
@register("MyComponentBeingLooped")
|
||||
class MyComponentBeingLooped(Component):
|
||||
template = """
|
||||
{% component "MyComponentWithASlot" %}
|
||||
{% fill "my_slot" %}
|
||||
{% component "MyInnerComponent" / %}
|
||||
{% endfill %}
|
||||
{% endcomponent %}
|
||||
"""
|
||||
|
||||
@register("MyInnerComponent")
|
||||
class MyInnerComponent(Component):
|
||||
template = "Hello!"
|
||||
|
||||
@register("MyComponentWithASlot")
|
||||
class MyComponentWithASlot(Component):
|
||||
template = "CAPTURER"
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
seen_slots.append(self.input.slots["my_slot"])
|
||||
|
||||
MyTopLevelComponent.render()
|
||||
|
||||
assert len(seen_slots) == 3
|
||||
|
||||
results = [slot().strip() for slot in seen_slots]
|
||||
assert results == [
|
||||
"<!-- _RENDERED MyInnerComponent_fb676b,ca1bc49,, -->Hello!",
|
||||
"<!-- _RENDERED MyInnerComponent_fb676b,ca1bc4a,, -->Hello!",
|
||||
"<!-- _RENDERED MyInnerComponent_fb676b,ca1bc4b,, -->Hello!",
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue