Skip to content

Commit

Permalink
Prevent duplicate renderer updates with invalid children
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored and jaltekruse committed Feb 27, 2023
1 parent 6834848 commit 14db5a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
29 changes: 28 additions & 1 deletion cypress/e2e/DoenetML/tagSpecific/mathinput.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7537,7 +7537,7 @@ describe('MathInput Tag Tests', function () {
cy.get('#\\/m2 .mjx-mrow').eq(0).should('have.text', '\uff3f')
cy.get('#\\/m3 .mjx-mrow').eq(0).should('have.text', '\uff3f')


cy.get('#\\/mi1 textarea').type("12,345{enter}", { force: true });
cy.get('#\\/mi2 textarea').type("12,345{enter}", { force: true });
cy.get('#\\/mi3 textarea').type("12,345{enter}", { force: true });
Expand Down Expand Up @@ -7602,4 +7602,31 @@ describe('MathInput Tag Tests', function () {

});

it('mathinput updates not messed up with invalid child logic containing a composite', () => {
cy.window().then(async (win) => {
win.postMessage({
doenetML: `
<ol>
<math name="m">x</math> $m
<li><mathinput name="mi" /> <math name="m2" copySource="mi" /></li>
</ol>
`}, "*");
});

cy.get('#\\/m .mjx-mrow').eq(0).should('have.text', 'x')

cy.get('#\\/mi textarea').type("sqrt4{enter}", { force: true });

cy.get('#\\/m2 .mjx-mrow').should('contain.text', '√4')
cy.get('#\\/m2 .mjx-mrow').eq(0).should('have.text', '√4')

cy.window().then(async (win) => {
let stateVariables = await win.returnAllStateVariables1();
expect(stateVariables["/mi"].stateValues.value).eqls(["apply", "sqrt", 4]);
expect(stateVariables["/m2"].stateValues.value).eqls(["apply", "sqrt", 4]);
});


});

});
15 changes: 15 additions & 0 deletions src/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8421,6 +8421,21 @@ export default class Core {
actionId,
});


if (this.updateInfo.componentsToUpdateRenderers.length > 0) {
// remove any names that were just updated
// (which can happen if tried to expand composites while updating renderers)

let newNames = [...new Set(this.updateInfo.componentsToUpdateRenderers)];
this.updateInfo.componentsToUpdateRenderers = [];
for (let name of newNames) {
if (!componentNamesToUpdate.includes(name)) {
this.updateInfo.componentsToUpdateRenderers.push(name);
}
}
}


// updating renderer instructions could trigger more composite updates
// (presumably from deriving child results)
// if so, make replacement changes and update renderer instructions again
Expand Down

0 comments on commit 14db5a6

Please sign in to comment.