Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded when using a localized text and global variable #29

Closed
TimeBather opened this issue Feb 9, 2023 · 10 comments

Comments

@TimeBather
Copy link

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.

@mark-friedman
Copy link
Collaborator

Thanks for the bug report, @TimeBather! I think I know the likely cause.

@mark-friedman
Copy link
Collaborator

@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!

mit-app-inventor-blockly-block-lexical-variables-0.0.13.tgz

@TimeBather
Copy link
Author

Thank you for fixing it. But it seems that in some edge cases, this problem still exists.
image

Steps to reproduce

  1. Add a global variable declaration and a get variable block.
    image

  2. Remove the variable name
    image

  3. And the name of the variable get will changed to global _ , and the problem occured
    image
    image

@mark-friedman
Copy link
Collaborator

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.

mark-friedman added a commit that referenced this issue Mar 2, 2023
@mark-friedman
Copy link
Collaborator

@TimeBather Would you mind trying to re-install and test the following new version of the packed file?

mit-app-inventor-blockly-block-lexical-variables-0.0.13.tgz

@TimeBather
Copy link
Author

TimeBather commented Mar 5, 2023

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

image
image
image

  • [V] I did not click it, but it were automatically selected , and it will recover if I close it.
    image

@mark-friedman
Copy link
Collaborator

Thanks again for testing, @TimeBather. I'll take another look.

@mark-friedman
Copy link
Collaborator

@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

@TimeBather
Copy link
Author

I'm sorry that I forget to clean the cache of my package manager. And it works!
Thank you for fixing it.

@mark-friedman
Copy link
Collaborator

The fix for this has been merged and has been published to the NPM package registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants