Skip to content

Need a method to choose JS engine. #360

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

Closed
holmesconan opened this issue Dec 14, 2016 · 8 comments
Closed

Need a method to choose JS engine. #360

holmesconan opened this issue Dec 14, 2016 · 8 comments

Comments

@holmesconan
Copy link

I am trying to develop React.NET project under macOS. The VroomJS need to be compiled and I am working on it.

As I reading the source of React.NET, it already add Chakra as a candidate JS engine, but the GetEngine method just tried each factory and return the first that works. I have tried to install JavaScriptEngineSwitcher and add it to IServiceCollection, but the ReactEnvironment remain try the VroomJS engine. I don't find how to replace the factory in the TinyIoC container.

I thought we can have a option for the chosen of JS engine. That's more convenient.

I am working on building my VroomJS engine on macOS. If that works, I could try to fix this.

@holmesconan
Copy link
Author

Perhaps a simple solution is to add a try-catch block to wrap the AddVroom method. then this factory will not be added since it failed to initialize VroomJS.

I found that the JavaScript Engine Switcher already update to v2.1.2 version, but the dependencies still be 2.0.0 of React.NET 3.0.0.

@holmesconan
Copy link
Author

A PR has been made.

@dima117
Copy link

dima117 commented Apr 3, 2017

+1

I have the same problem.

@dima117
Copy link

dima117 commented Apr 3, 2017

I suggest to remove the engine selection functionality from the package and assigning responsibility for it to the user who configures React.NET. For example, it will be similarly to the DBMS selection in the Entity Framework Core.

@Daniel15
Copy link
Member

Daniel15 commented Apr 3, 2017

I suggest to remove the engine selection functionality from the package and assigning responsibility for it to the user who configures React.NET

This is already handled - ReactJS.NET will only register engines if you have not registered them yourself: https://github.com/reactjs/React.NET/blob/master/src/React.Core/JavaScriptEngineFactory.cs#L360-L364. You just need to ensure you register the engines before registering ReactJS.NET.

@dima117
Copy link

dima117 commented Apr 3, 2017

You just need to ensure you register the engines before registering ReactJS.NET.

The problem is that the default configuration results in an error.

I tried the following code (according to this example):

JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
engineSwitcher.EngineFactories.Add(new JintJsEngineFactory());
engineSwitcher.DefaultEngineName = "JintJsEngine";

Initializer.Initialize(registration => registration.AsSingleton());

var container = React.AssemblyRegistration.Container;
container.Register<ICache, NullCache>();
container.Register<IFileSystem, SimpleFileSystem>();

ReactSiteConfiguration.Configuration
  .SetReuseJavaScriptEngines(false)
  .AddScript("Sample.jsx");

And I had an error in this line (there is existing issue).

I think, the error is in my code. But it's hard for me to know exactly where it is, because the configuration API uses implicit logic, which is dependent on global variables (JsEngineSwitcher).

It would be much easier if the engine had to be explicitly specified (and get an error if it was specified incorrectly)

UPD. I use it in .NET Core on macOS.

@Taritsyn
Copy link
Contributor

Taritsyn commented Apr 9, 2017

I suggest to remove the engine selection functionality from the package and assigning responsibility for it to the user who configures React.NET. For example, it will be similarly to the DBMS selection in the Entity Framework Core.

@Daniel15 @dima117 @holmescn Good idea, but I would go further: need to remove from the React.Core all JavaScriptEngineSwitcher.* dependencies except for the JavaScriptEngineSwitcher.Core. Thus, users will not need to download unnecessary dependencies. Anyway we need to install manually the packages with native assemblies for the JavaScriptEngineSwitcher.V8 and JavaScriptEngineSwitcher.ChakraCore. I use this approach in the Bundle Transformer and it works great for many years. This approach adds only one additional step in configuring of library - selection and installation of JavaScript engine.

All problems, that prevented to do it have already been resolved in latest versions of the JavaScript Engine Switcher:

  1. For a long time already when using the MSIE JavaScript Engine in different threads there are no errors.
  2. MSIE JavaScript Engine and JavaScriptEngineSwitcher.ChakraCore are run in a separate threads with increased stack size.
  3. Created a module, that supports VroomJs - JavaScriptEngineSwitcher.Vroom

@dustinsoftware
Copy link
Member

We've updated the JS engine registration logic in 4.0, please update if you're still encountering issues.

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

5 participants