Maximum call stack size exceeded when using a localized text and global variable
TimeBather opened this issue · 10 comments
Error:
Uncaught RangeError: Maximum call stack size exceeded
at new InputConnection$$module$build$src$core$renderers$measurables$input_connection (input_connection.ts:43:3)
at new StatementInput$$module$build$src$core$renderers$measurables$statement_input (statement_input.ts:37:5)
at new StatementInput$$module$build$src$core$renderers$geras$measurables$statement_input (statement_input.ts:38:5)
at RenderInfo$$module$build$src$core$renderers$geras$info.addInput_ (info.ts:93:31)
at RenderInfo$$module$build$src$core$renderers$geras$info.createRows_ (info.ts:212:12)
at RenderInfo$$module$build$src$core$renderers$geras$info.measure (info.ts:165:10)
at Renderer$$module$build$src$core$renderers$geras$renderer.render (renderer.ts:284:10)
at BlockSvg$$module$build$src$core$block_svg.render (block_svg.ts:1670:36)
at BlockSvg$$module$build$src$core$block_svg.render (block_svg.ts:1676:23)
at FieldLexicalVariable.forceRerender (field.ts:946:39)
FieldLexicalVariable.getNamesInScope @ field_lexical_variable.js:203
FieldLexicalVariable.getNamesInScope @ field_lexical_variable.js:197
FieldLexicalVariable.dropdownCreate @ field_lexical_variable.js:288
checkDropDownContainsValidValue @ warningHandler.js:114
checkErrors @ warningHandler.js:51
FieldLexicalVariable.dropdownChange @ field_lexical_variable.js:421
setValue @ field.ts:978
setValue @ field_lexical_variable.js:114
checkDropDownContainsValidValue @ warningHandler.js:128
checkErrors @ warningHandler.js:51
FieldLexicalVariable.dropdownChange @ field_lexical_variable.js:421
setValue @ field.ts:978
setValue @ field_lexical_variable.js:114
Enviornment and related Codes
Blockly.Msg['LANG_VARIABLES_GLOBAL_PREFIX'] = '[全局变量]';
Then, when we place a global variable declaration and a variable-read block,then change the variable dropdown into the global variable , the problem occurs.
Analysis for this bug
First , the dropdown updated ,and trigged dropdownChange
FieldLexicalVariable.dropdownChange = function(text) {
if (text) {
this.doValueUpdate_(text);
const topWorkspace = this.sourceBlock_.workspace.getTopWorkspace();
if (topWorkspace.getWarningHandler) {
topWorkspace.getWarningHandler().checkErrors(this.sourceBlock_);
}
}
// window.setTimeout(Blockly.Variables.refreshFlyoutCategory, 1);
};
Then , in some steps, the doValueUpdate calls a function called FieldLexicalVariable.setValue
, it doesn't supporting the localize
setValue(text) {
if (text && text !== " ") {
const parts = text.split(" ");
if (parts.length == 2 && parts[0] !== "global") {
text = "global " + parts[1];
}
}
super.setValue(text);
}
So the setValue update the text again and again , until the JavaScript engine throw an Error because the stack size exceed.
Thanks for the bug report, @TimeBather! I think I know the likely cause.
@TimeBather Sorry that it took so long for me to get this fixed. I think I have it done. Before I release it to npm, could you please test it in your environment for me? I've created an npm pack
file for you to use and attached it to this message (with a link below). The easiest way to use it would probably be to download the file to the directory containing you project and type the following at the command line:
npm install mit-app-inventor-blockly-block-lexical-variables-0.0.13.tgz
Let me know how it goes!
Thanks for testing and finding the error case, @TimeBather! I'll take a look and hopefully get back to you soon with a revised, fixed, package.
@TimeBather Would you mind trying to re-install and test the following new version of the packed file?
I think it still does not solve the problem.
If I change the variable names in the title to empty, it still throws maximum call stack size exceeded errors.
But if I click the dropdown of the get variable menu, and then close it without choosing, it recovered.
Reproduction
Thanks again for testing, @TimeBather. I'll take another look.
@TimeBather, I'm not seeing the behavior that you mention with the latest fixed version of the package. I wonder if there was some cacheing that interfered with the fix. Can you please re-download the npm pack
file from here: mit-app-inventor-blockly-block-lexical-variables-0.0.13.tgz then clear your npm files and cache and re-install:
$ rm -rf node_modules
$ npm cache clean
$ npm install
$ npm install mit-app-inventor-blockly-block-lexical-variables-0.0.13.tgz
I'm sorry that I forget to clean the cache of my package manager. And it works!
Thank you for fixing it.
The fix for this has been merged and has been published to the NPM package registry.