1

Since I've decided to switch to server-side rendering from client-side react, I began to create my components and use them in the app.

However I came across this error:

Unknown error (RangeError); potential stack overflow detected

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Microsoft.ClearScript.ScriptEngineException: Unknown error (RangeError); potential stack overflow detected

And this is a part from the stack-trace

[ScriptEngineException: Unknown error (RangeError); potential stack overflow detected]
   V8Exception.ThrowScriptEngineException(V8Exception* ) +169
   Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard) +462
   Microsoft.ClearScript.V8.<>c__DisplayClass1b.<Execute>b__19() +197
   Microsoft.ClearScript.ScriptEngine.ScriptInvoke(Func`1 func) +70
   Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke(Func`1 func) +49
   Microsoft.ClearScript.V8.<>c__DisplayClass25`1.<ScriptInvoke>b__24() +45
   Microsoft.ClearScript.V8.?A0x792c8756.LockCallback(Void* pvArg) +9
   Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction) +176
   Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke(Func`1 func) +118
   Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard) +118
   JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression) +89

So I don't know what causes this error but I think it is some code that goes in a loop or something similar. Furthermore if I refresh the page this error goes away and if I continue to refresh intensively it shows up again which is very frustrating.

2
  • 1
    well, if you have a potential stack overflow, you came to the right place Commented Jul 28, 2016 at 14:12
  • that was a good one Commented Jul 28, 2016 at 14:14

2 Answers 2

3

I was getting the same error (web app in azure) and after some investigation and tests, setting SetAllowMsieEngine to true did in fact fixed the issue also to me.

As Luke McGregor said, this seems to be an issue with V8ScriptEngine and using SetAllowMsieEngine does the job, however this method is latest version of react.net is deprecated and is recommended to "managed in the JavaScriptEngineSwitcher configuration".

So the solution I found so far is to switch js engine switcher by setting it directly in code:

JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
engineSwitcher.EngineFactories
    .AddChakraCore()
    .AddMsie( new MsieSettings() { EngineMode = JsEngineMode.Auto } );

engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;

Like this I'm using ChakraCore engine rather than default V8 which was causing the error.

So far, during our performance tests with around 250 concurrent requests, we do not have this error anymore when previously in the same conditions for sure this error would have occurred.

Sign up to request clarification or add additional context in comments.

Comments

1

This is a known issue, see https://github.com/reactjs/React.NET/issues/190

The work around is to not use V8 to do the render ie:

app.UseReact(config =>
        {
            config
                // ..other configuration settings
                .SetAllowMsieEngine(true);
        });

8 Comments

yes, I saw this github issue when I searched for this error and apparently it was the only relevant post on the subject so far. Anyway where should I insert the code you provided? I suspect it has to be in the Startup.cs file but my app doesn't have a UseReact() method...
@MartinShishkov By default it sits in App_Start\ReactConfig.cs (on ReactSiteConfiguration.Configuration) but startup is the nicer place
Do you mean I should do ReactSiteConfiguration.Configuration.SetAllowMsieEngine(true); in the Configure() method in ReactConfig.cs?
Yup, I think that should stop the exception, the comment on the method has changed slightly since last i looked. But the idea is not to use V8
Okay, I have set the configuration and we'll see where this leads. Furthermore on the github issue that you suggested there was this link - https://clearscript.codeplex.com/discussions/650824 and they say that this line of code (typeof _myVariable !== 'undefined') might cause some problems. I have the same statement in my code so do you think I should replace it with something similar?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.