Skip to content

Commit

Permalink
πŸ› Use the correct renderer/element when reactively updating properties
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jun 14, 2024
1 parent cf950f4 commit f6fd7a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/core/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ function logLog(type, args) {
// Some Symbols
Hawkejs.RENDER_INSTRUCTION = Symbol('render_instruction');
Hawkejs.DELAY_SYNC_RENDER = Symbol('delay_sync_render');
Hawkejs.ANCESTOR_ELEMENT = Symbol('ancestor_element');
Hawkejs.CREATED_MANUALLY = Symbol('created_manually');
Hawkejs.REACTIVE_VALUES = Symbol('reactive_values');
Hawkejs.APPLIED_OPTIONS = Symbol('applied_options');
Expand Down
19 changes: 17 additions & 2 deletions lib/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,17 @@ const updateElementProperty = (element, setter, getter, optional, key, config) =

// We have to execute the expression to get the new value
let renderer = new Hawkejs.Renderer(element.hawkejs);
renderer.active_variables = element[Hawkejs.VARIABLES];
renderer[Hawkejs.ANCESTOR_ELEMENT] = element;

let variables = element[Hawkejs.VARIABLES];

if (variables) {
renderer.active_variables = variables;

// The variables instance might still be holding on to an old renderer
// Make sure it's this new one!
variables.hawkejs_renderer = renderer;
}

let new_value = renderer.parseRuntimeExpression(config.expression);

Expand Down Expand Up @@ -720,6 +730,11 @@ Renderer.setProperty(function theme() {
Renderer.setProperty(function current_element() {

if (this.on_template_root_level) {

if (this[Hawkejs.ANCESTOR_ELEMENT]) {
return this[Hawkejs.ANCESTOR_ELEMENT];
}

if (this.current_variables.has('$ancestor_element')) {
return this.current_variables.get('$ancestor_element');
}
Expand Down Expand Up @@ -2320,7 +2335,7 @@ Renderer.setMethod(function ensureElementOptions(element) {
}

// Manually created elements will have already called this
if (!element[Hawkejs.CREATED_MANUALLY]) {
if (!element[Hawkejs.CREATED_MANUALLY] && !element[Hawkejs.CONSTRUCTED]) {
Hawkejs.CustomElementConstructor.call(element);
ElClass.call(element);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/core/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Variables.setProperty(function length() {
*/
Variables.setProperty(function hawkejs_renderer() {
return this[RENDERER];
}, function setHawkejsRenderer(value) {
this[RENDERER] = value;
});

/**
Expand Down

0 comments on commit f6fd7a0

Please sign in to comment.