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
Support/document usage of JSComponent within code-based DotvvmControls/CompositeControls #1802
Comments
Yea, code-only components currently cannot reference and initialize view modules. It is a fundamental issue that view module instances are identified using the JavaScript HTMLElement and found by walking the ancestor chain. Initializing a new view module in the code control would thus break all references to the page view module from inside of any templates the control has. Our current solution is to not support That being said, you can use dotvvm.registerGlobalComponent("your-component-name", registerReactControl(... same as in view module $controls)) This will make the component available to all pages and, crucially, to the In case that doesn't suit your needs, if you require the view module for some reason, there are two other ways to work around it:
jsComponent.SetValue(Internal.ReferencedViewModuleInfoProperty,
this.GetAllAncestors().Select(c => c.GetValue(Internal.ReferencedViewModuleInfoProperty)).First(i => i != null)) Or, if you want to make the code future-proof against us hopefully resolving the core issue, copy the [ApplyControlStyle]
public static void AddReferencedViewModuleInfoProperty(ResolvedControl control)
{
if (control.TreeRoot.TryGetProperty(Internal.ReferencedViewModuleInfoProperty, out var x))
{
var value = ((ResolvedPropertyValue)x).Value;
control.SetProperty(new ResolvedPropertyValue(Internal.ReferencedViewModuleInfoProperty, value));
}
} and then access the property by calling Same trick by the way applies to using |
JSComponents function only when used in the dothtml syntax as documented and don't work properly when used from within code-based DotvvmControls/CompositeControls. In particular, no
dotvvm-with-view-modules
KO binding comment gets rendered.Scenario
Let's have a JS component wrapping a React component, for example,
recharts
. When I use this component like this:...all is well, and, in the browser, the component is found and initialized.
However, when I use this component from within a CompositeControl:
The
dotvvm-with-view-modules
binding is missing in the page, the JSComponent is rendered without theview
property, and thefindComponent
function acan not find control Recharts
error.When I try to avoid this by adding
@js dotvvm-recharts.js
, despite theRequiredResource
control already in theRechartsComposite
, thedotvvm-with-view-modules
is present, butview
property is still not rendered, and thus the component is still not found.Is there a method other than
RequiredResource
that would allow a control to include a JS module?The text was updated successfully, but these errors were encountered: