Skip to content

Commit

Permalink
Merge pull request #1769 from riganti/warning-dotcontrol-DotvvmView
Browse files Browse the repository at this point in the history
Warning when DotvvmView is used as control
  • Loading branch information
exyi authored Jan 31, 2024
2 parents 2c212a8 + a0a11f8 commit 1801018
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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());
}
}

}

0 comments on commit 1801018

Please sign in to comment.