Skip to content

Commit

Permalink
πŸ› Fix another reactive re-rendering scope bug
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jun 14, 2024
1 parent f6fd7a0 commit 25b205c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ Renderer.setProperty(function current_element() {
if (this.current_variables.has('$ancestor_element')) {
return this.current_variables.get('$ancestor_element');
}

return;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/element/custom_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,10 @@ function renderContentsWithTemplate(element, template, variables, slot_data, ple
variables.setFromTemplate('child_nodes', slot_data.child_nodes);
}

element.hawkejs_renderer = renderer;
renderer[Hawkejs.ANCESTOR_ELEMENT] = element;
variables.setFromTemplate('$ancestor_element', element);
variables.hawkejs_renderer = renderer;

Hawkejs.series(next => {
renderer.renderTemplate(template, variables, String(render_counter++)).done(next);
Expand Down
37 changes: 33 additions & 4 deletions test/10-expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,15 +1282,15 @@ This should be a converted variable:
state:message={% my_name{:} %}
>
{{ state:message{:} }}-{{ attr:name }}-{{ prop:id }}
<span>{{ state:message{:} }}-{{ attr:name }}-{{ prop:id }}</span>
<span name="A">{{ state:message{:} }}-{{ attr:name }}-{{ prop:id }}</span>
<div>{{ var:foo{:} }}</div>
</my-text>
`,
// The expected result
`
<my-text id="l" name="t1">
init-t1-l
<span>init--</span>
<span name="A">init-A-</span>
<div>bar</div>
</my-text>
`,
Expand All @@ -1302,11 +1302,40 @@ This should be a converted variable:
`
<my-text id="l" name="t1">
second-t1-l
<span>second--</span>
<span name="A">second-A-</span>
<div>baz</div>
</my-text>
`,
]
],
// Test to see if `updateElementProperty()` has the correct renderer
[
// Prepare the state & variables
(vars) => {
state = {};
state.name_one = vars.set('name_one', Optional('init1'));
state.name_two = vars.set('name_two', Optional('init2'));
},
// Initial template
`
<my-text id="one" state:message={% name_one{:} %}><i title={% state:message{:} %}></i></my-text>
<my-text id="two" state:message={% name_two{:} %}><i title={% state:message{:} %}></i></my-text>
`,
// Expected result
`
<my-text id="one"><i title="init1"></i></my-text>
<my-text id="two"><i title="init2"></i></my-text>
`,
(vars) => {
state.name_one.value = 'change1';
state.name_two.value = 'change2';
},
// New expected result
`
<my-text id="one"><i title="change1"></i></my-text>
<my-text id="two"><i title="change2"></i></my-text>
`,

],
];

createReactiveTests(tests);
Expand Down

0 comments on commit 25b205c

Please sign in to comment.