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

Warning when DotvvmView is used as control #1769

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ private IAbstractControl ProcessObjectElement(DothtmlElementNode element, IDataC
constructorParameters = new[] { element.FullTagName };
element.AddError($"The control <{element.FullTagName}> could not be resolved! Make sure that the tagPrefix is registered in DotvvmConfiguration.Markup.Controls collection!");
}
if (controlMetadata.VirtualPath is {} && controlMetadata.Type.IsAssignableTo(ResolvedTypeDescriptor.Create(typeof(DotvvmView))))
{
element.TagNameNode.AddWarning($"The markup control <{element.FullTagName}> has a baseType DotvvmView. Please make sure that the control file has .dotcontrol file extension. This will work, but causes unexpected issues, for example @js directive will not work in this control.");
}
var control = treeBuilder.BuildControl(controlMetadata, element, dataContext);
control.ConstructorParameters = constructorParameters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
using DotVVM.Framework.Utils;
using DotVVM.Framework.Controls;
using DotVVM.Framework.Compilation.Parser.Dothtml.Parser;
using DotVVM.Framework.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Controls.Infrastructure;


namespace DotVVM.Framework.Tests.Runtime.ControlTree
Expand Down Expand Up @@ -100,6 +104,30 @@ @viewModel System.DateTime
Assert.AreEqual(1, literal.DothtmlNode.NodeWarnings.Count());
Assert.AreEqual("Evaluation of method \"ToBrowserLocalTime\" on server-side may yield unexpected results.", literal.DothtmlNode.NodeWarnings.First());
}

[TestMethod]
public void DefaultViewCompiler_DotvvmView_Used_As_Control_Warning()
{
var files = new FakeMarkupFileLoader();
files.MarkupFiles["TestControl.dothtml"] = """
@viewModel object
test
""";
var config = DotvvmTestHelper.CreateConfiguration(s => {
s.AddSingleton<IMarkupFileLoader>(files);
});
config.Markup.AddMarkupControl("cc", "TestControl", "TestControl.dothtml");

var markup = DotvvmTestHelper.ParseResolvedTree("""
@viewModel object
<cc:TestControl Styles.Tag=this />
""", configuration: config);
var control = markup.Content.SelectRecursively(c => c.Content).Single(c => c.Properties.ContainsKey(Styles.TagProperty));
Assert.AreEqual(typeof(DotvvmView), control.Metadata.Type);
var element = (DothtmlElementNode)control.DothtmlNode;
XAssert.Contains("The markup control <cc:TestControl> has a baseType DotvvmView", element.TagNameNode.NodeWarnings.First());
Assert.AreEqual(1, element.TagNameNode.NodeWarnings.Count());
}
}

}
Loading