From 844a18ad097eb52cdbcc3edf02e33bba0bc0e766 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 24 Sep 2020 08:24:50 -0700 Subject: [PATCH] Remove Microsoft.Components.Web.Extensions (#26256) The package was marked as non-shipping but we continued to build and test it. This change removes it. A copy of this code exists in asplabs so all is not lost. --- AspNetCore.sln | 18 -- eng/ProjectReferences.props | 1 - src/Components/Components.slnf | 1 - src/Components/ComponentsNoDeps.slnf | 1 - .../HeadManagementJSRuntimeExtensions.cs | 28 --- .../src/HeadManagement/HeadTagBase.cs | 67 ------- .../Web.Extensions/src/HeadManagement/Link.cs | 14 -- .../Web.Extensions/src/HeadManagement/Meta.cs | 14 -- .../src/HeadManagement/TagElement.cs | 22 --- .../src/HeadManagement/Title.cs | 37 ---- .../src/HeadManagement/TitleElement.cs | 17 -- ...spNetCore.Components.Web.Extensions.csproj | 21 --- .../src/Properties/AssemblyInfo.cs | 3 - .../Web.Extensions/src/PublicAPI.Shipped.txt | 1 - .../src/PublicAPI.Unshipped.txt | 18 -- .../Web.Extensions/src/wwwroot/headManager.js | 102 ---------- .../ServerExecutionTests/PrerenderingTest.cs | 33 ---- .../test/E2ETest/Tests/HeadComponentsTest.cs | 175 ------------------ .../BasicTestApp/BasicTestApp.csproj | 1 - .../test/testassets/BasicTestApp/Index.razor | 1 - .../BasicTestApp/ModifyHeadComponent.razor | 119 ------------ .../PrerenderedHeadComponent.razor | 45 ----- .../test/testassets/BasicTestApp/Program.cs | 5 +- 23 files changed, 1 insertion(+), 743 deletions(-) delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/HeadManagementJSRuntimeExtensions.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/HeadTagBase.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/Link.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/Meta.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/TagElement.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/Title.cs delete mode 100644 src/Components/Web.Extensions/src/HeadManagement/TitleElement.cs delete mode 100644 src/Components/Web.Extensions/src/Microsoft.AspNetCore.Components.Web.Extensions.csproj delete mode 100644 src/Components/Web.Extensions/src/Properties/AssemblyInfo.cs delete mode 100644 src/Components/Web.Extensions/src/PublicAPI.Shipped.txt delete mode 100644 src/Components/Web.Extensions/src/PublicAPI.Unshipped.txt delete mode 100644 src/Components/Web.Extensions/src/wwwroot/headManager.js delete mode 100644 src/Components/test/E2ETest/Tests/HeadComponentsTest.cs delete mode 100644 src/Components/test/testassets/BasicTestApp/ModifyHeadComponent.razor delete mode 100644 src/Components/test/testassets/BasicTestApp/PrerenderedHeadComponent.razor diff --git a/AspNetCore.sln b/AspNetCore.sln index 28551367a76c..ceb029889f9e 100644 --- a/AspNetCore.sln +++ b/AspNetCore.sln @@ -1391,10 +1391,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerComparison.Functional EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Testing.Tests", "src\Testing\test\Microsoft.AspNetCore.Testing.Tests.csproj", "{1542DC58-1836-4191-A9C5-51D1716D2543}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Web.Extensions", "Web.Extensions", "{F71FE795-9923-461B-9809-BB1821A276D0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.Web.Extensions", "src\Components\Web.Extensions\src\Microsoft.AspNetCore.Components.Web.Extensions.csproj", "{8294A74F-7DAA-4B69-BC56-7634D93C9693}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sdk", "Sdk", "{FED4267E-E5E4-49C5-98DB-8B3F203596EE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.BlazorWebAssembly", "src\Components\WebAssembly\Sdk\src\Microsoft.NET.Sdk.BlazorWebAssembly.csproj", "{6B2734BF-C61D-4889-ABBF-456A4075D59B}" @@ -6701,18 +6697,6 @@ Global {1542DC58-1836-4191-A9C5-51D1716D2543}.Release|x64.Build.0 = Release|Any CPU {1542DC58-1836-4191-A9C5-51D1716D2543}.Release|x86.ActiveCfg = Release|Any CPU {1542DC58-1836-4191-A9C5-51D1716D2543}.Release|x86.Build.0 = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|x64.ActiveCfg = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|x64.Build.0 = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|x86.ActiveCfg = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Debug|x86.Build.0 = Debug|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|Any CPU.Build.0 = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|x64.ActiveCfg = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|x64.Build.0 = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|x86.ActiveCfg = Release|Any CPU - {8294A74F-7DAA-4B69-BC56-7634D93C9693}.Release|x86.Build.0 = Release|Any CPU {6B2734BF-C61D-4889-ABBF-456A4075D59B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6B2734BF-C61D-4889-ABBF-456A4075D59B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B2734BF-C61D-4889-ABBF-456A4075D59B}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -8080,8 +8064,6 @@ Global {3CBC4802-E9B8-48B7-BC8C-B0AFB9EEC643} = {0ACCEDA7-339C-4B4D-8DD4-1AC271F31C04} {48E64014-B249-4644-8AEB-CDEE8ABA0DC2} = {3CBC4802-E9B8-48B7-BC8C-B0AFB9EEC643} {1542DC58-1836-4191-A9C5-51D1716D2543} = {05A169C7-4F20-4516-B10A-B13C5649D346} - {F71FE795-9923-461B-9809-BB1821A276D0} = {60D51C98-2CC0-40DF-B338-44154EFEE2FF} - {8294A74F-7DAA-4B69-BC56-7634D93C9693} = {F71FE795-9923-461B-9809-BB1821A276D0} {FED4267E-E5E4-49C5-98DB-8B3F203596EE} = {562D5067-8CD8-4F19-BCBB-873204932C61} {6B2734BF-C61D-4889-ABBF-456A4075D59B} = {FED4267E-E5E4-49C5-98DB-8B3F203596EE} {83371889-9A3E-4D16-AE77-EB4F83BC6374} = {FED4267E-E5E4-49C5-98DB-8B3F203596EE} diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props index 43a998225972..a02777218241 100644 --- a/eng/ProjectReferences.props +++ b/eng/ProjectReferences.props @@ -141,7 +141,6 @@ - diff --git a/src/Components/Components.slnf b/src/Components/Components.slnf index 50973b2288a5..d023481b9575 100644 --- a/src/Components/Components.slnf +++ b/src/Components/Components.slnf @@ -101,7 +101,6 @@ "src\\Components\\test\\testassets\\GlobalizationWasmApp\\GlobalizationWasmApp.csproj", "src\\Components\\benchmarkapps\\Wasm.Performance\\Driver\\Wasm.Performance.Driver.csproj", "src\\Components\\benchmarkapps\\Wasm.Performance\\TestApp\\Wasm.Performance.TestApp.csproj", - "src\\Components\\Web.Extensions\\src\\Microsoft.AspNetCore.Components.Web.Extensions.csproj", "src\\Components\\WebAssembly\\Server\\test\\Microsoft.AspNetCore.Components.WebAssembly.Server.Tests.csproj", "src\\Components\\WebAssembly\\Authentication.Msal\\src\\Microsoft.Authentication.WebAssembly.Msal.csproj", "src\\Components\\WebAssembly\\JSInterop\\src\\Microsoft.JSInterop.WebAssembly.csproj", diff --git a/src/Components/ComponentsNoDeps.slnf b/src/Components/ComponentsNoDeps.slnf index 3c95b3b7caca..0596b3bc64a1 100644 --- a/src/Components/ComponentsNoDeps.slnf +++ b/src/Components/ComponentsNoDeps.slnf @@ -16,7 +16,6 @@ "src\\Components\\Samples\\BlazorServerApp\\BlazorServerApp.csproj", "src\\Components\\Server\\src\\Microsoft.AspNetCore.Components.Server.csproj", "src\\Components\\Server\\test\\Microsoft.AspNetCore.Components.Server.Tests.csproj", - "src\\Components\\Web.Extensions\\src\\Microsoft.AspNetCore.Components.Web.Extensions.csproj", "src\\Components\\WebAssembly\\Authentication.Msal\\src\\Microsoft.Authentication.WebAssembly.Msal.csproj", "src\\Components\\WebAssembly\\DevServer\\src\\Microsoft.AspNetCore.Components.WebAssembly.DevServer.csproj", "src\\Components\\WebAssembly\\JSInterop\\src\\Microsoft.JSInterop.WebAssembly.csproj", diff --git a/src/Components/Web.Extensions/src/HeadManagement/HeadManagementJSRuntimeExtensions.cs b/src/Components/Web.Extensions/src/HeadManagement/HeadManagementJSRuntimeExtensions.cs deleted file mode 100644 index aafbbf194e96..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/HeadManagementJSRuntimeExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.JSInterop; - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - internal static class HeadManagementJSRuntimeExtensions - { - private const string JsFunctionsPrefix = "_blazorHeadManager"; - - public static ValueTask SetTitleAsync(this IJSRuntime jsRuntime, string title) - { - return jsRuntime.InvokeVoidAsync($"{JsFunctionsPrefix}.setTitle", title); - } - - public static ValueTask AddOrUpdateHeadTagAsync(this IJSRuntime jsRuntime, TagElement tag, string id) - { - return jsRuntime.InvokeVoidAsync($"{JsFunctionsPrefix}.addOrUpdateHeadTag", tag, id); - } - - public static ValueTask RemoveHeadTagAsync(this IJSRuntime jsRuntime, string id) - { - return jsRuntime.InvokeVoidAsync($"{JsFunctionsPrefix}.removeHeadTag", id); - } - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/HeadTagBase.cs b/src/Components/Web.Extensions/src/HeadManagement/HeadTagBase.cs deleted file mode 100644 index fce4271b20f5..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/HeadTagBase.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components.Rendering; -using Microsoft.JSInterop; - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - /// - /// Serves as a base for components that represent tags in the HTML head. - /// - public abstract class HeadTagBase : ComponentBase, IDisposable - { - private readonly string _id = Guid.NewGuid().ToString("N"); - - private TagElement _tagElement; - - private bool _hasRendered; - - [Inject] - private IJSRuntime JSRuntime { get; set; } = default!; - - /// - /// Gets or sets a collection of additional attributes that will be applied to the meta element. - /// - [Parameter(CaptureUnmatchedValues = true)] - public IReadOnlyDictionary? Attributes { get; set; } - - /// - /// Gets the name of the tag being represented. - /// - protected abstract string TagName { get; } - - /// - protected override void OnParametersSet() - { - _tagElement = new TagElement(TagName, Attributes); - } - - /// - protected override async Task OnAfterRenderAsync(bool firstRender) - { - _hasRendered = true; - - await JSRuntime.AddOrUpdateHeadTagAsync(_tagElement, _id); - } - - /// - protected override void BuildRenderTree(RenderTreeBuilder builder) - { - builder.AddMarkupContent(0, $""); - } - - /// - public void Dispose() - { - if (_hasRendered) - { - _ = JSRuntime.RemoveHeadTagAsync(_id); - } - } - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/Link.cs b/src/Components/Web.Extensions/src/HeadManagement/Link.cs deleted file mode 100644 index 83cc193b747d..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/Link.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - /// - /// A component that adds a link tag to the HTML head. - /// - public sealed class Link : HeadTagBase - { - /// - protected override string TagName => "link"; - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/Meta.cs b/src/Components/Web.Extensions/src/HeadManagement/Meta.cs deleted file mode 100644 index e5100bbd4e21..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/Meta.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - /// - /// A component that adds a meta tag to the HTML head. - /// - public sealed class Meta : HeadTagBase - { - /// - protected override string TagName => "meta"; - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/TagElement.cs b/src/Components/Web.Extensions/src/HeadManagement/TagElement.cs deleted file mode 100644 index 3488eb1e156f..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/TagElement.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - internal readonly struct TagElement - { - public string Type => "tag"; - - public string TagName { get; } - - public IReadOnlyDictionary? Attributes { get; } - - public TagElement(string tagName, IReadOnlyDictionary? attributes) - { - TagName = tagName; - Attributes = attributes; - } - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/Title.cs b/src/Components/Web.Extensions/src/HeadManagement/Title.cs deleted file mode 100644 index f7cfd28359bd..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/Title.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Text.Json; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components.Rendering; -using Microsoft.JSInterop; - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - /// - /// A component that changes the title of the document. - /// - public sealed class Title : ComponentBase - { - [Inject] - private IJSRuntime JSRuntime { get; set; } = default!; - - /// - /// Gets or sets the value to use as the document's title. - /// - [Parameter] - public string Value { get; set; } = string.Empty; - - /// - protected override async Task OnAfterRenderAsync(bool firstRender) - { - await JSRuntime.SetTitleAsync(Value); - } - - /// - protected override void BuildRenderTree(RenderTreeBuilder builder) - { - builder.AddMarkupContent(0, $""); - } - } -} diff --git a/src/Components/Web.Extensions/src/HeadManagement/TitleElement.cs b/src/Components/Web.Extensions/src/HeadManagement/TitleElement.cs deleted file mode 100644 index c56d550ac294..000000000000 --- a/src/Components/Web.Extensions/src/HeadManagement/TitleElement.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Components.Web.Extensions.Head -{ - internal readonly struct TitleElement - { - public string Type => "title"; - - public string Title { get; } - - public TitleElement(string title) - { - Title = title; - } - } -} diff --git a/src/Components/Web.Extensions/src/Microsoft.AspNetCore.Components.Web.Extensions.csproj b/src/Components/Web.Extensions/src/Microsoft.AspNetCore.Components.Web.Extensions.csproj deleted file mode 100644 index 852f471d385a..000000000000 --- a/src/Components/Web.Extensions/src/Microsoft.AspNetCore.Components.Web.Extensions.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - $(DefaultNetCoreTargetFramework) - A collection of Blazor components for the web. - true - Microsoft.AspNetCore.Components - enable - false - - - - - - - - - - - - diff --git a/src/Components/Web.Extensions/src/Properties/AssemblyInfo.cs b/src/Components/Web.Extensions/src/Properties/AssemblyInfo.cs deleted file mode 100644 index 2e06371bc654..000000000000 --- a/src/Components/Web.Extensions/src/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Components.Web.Extensions.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Components/Web.Extensions/src/PublicAPI.Shipped.txt b/src/Components/Web.Extensions/src/PublicAPI.Shipped.txt deleted file mode 100644 index ab058de62d44..000000000000 --- a/src/Components/Web.Extensions/src/PublicAPI.Shipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable diff --git a/src/Components/Web.Extensions/src/PublicAPI.Unshipped.txt b/src/Components/Web.Extensions/src/PublicAPI.Unshipped.txt deleted file mode 100644 index f95bb5366e08..000000000000 --- a/src/Components/Web.Extensions/src/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,18 +0,0 @@ -#nullable enable -Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase -Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.Attributes.get -> System.Collections.Generic.IReadOnlyDictionary? -Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.Attributes.set -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.Dispose() -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.HeadTagBase() -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.Link -Microsoft.AspNetCore.Components.Web.Extensions.Head.Link.Link() -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.Meta -Microsoft.AspNetCore.Components.Web.Extensions.Head.Meta.Meta() -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.Title -Microsoft.AspNetCore.Components.Web.Extensions.Head.Title.Title() -> void -Microsoft.AspNetCore.Components.Web.Extensions.Head.Title.Value.get -> string! -Microsoft.AspNetCore.Components.Web.Extensions.Head.Title.Value.set -> void -abstract Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.TagName.get -> string! -override Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder! builder) -> void -override Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.OnAfterRenderAsync(bool firstRender) -> System.Threading.Tasks.Task! -override Microsoft.AspNetCore.Components.Web.Extensions.Head.HeadTagBase.OnParametersSet() -> void diff --git a/src/Components/Web.Extensions/src/wwwroot/headManager.js b/src/Components/Web.Extensions/src/wwwroot/headManager.js deleted file mode 100644 index e871b72afef4..000000000000 --- a/src/Components/Web.Extensions/src/wwwroot/headManager.js +++ /dev/null @@ -1,102 +0,0 @@ -(function () { - // Local helpers - - const blazorIdAttributeName = '_blazor_id'; - const headCommentRegularExpression = /\W*Head:[^{]*(.*)$/; - const prerenderedTags = []; - - function createHeadTag({ tagName, attributes }, id) { - const tagElement = document.createElement(tagName); - - // The id is undefined during prerendering - if (id) { - tagElement.setAttribute(blazorIdAttributeName, id); - } - - if (attributes) { - Object.keys(attributes).forEach(key => { - tagElement.setAttribute(key, attributes[key]); - }); - } - - document.head.appendChild(tagElement); - - return tagElement; - } - - function resolvePrerenderedHeadComponents(node) { - node.childNodes.forEach((childNode) => { - const headElement = parseHeadComment(childNode); - - if (headElement) { - applyPrerenderedHeadComponent(headElement); - } else { - resolvePrerenderedHeadComponents(childNode); - } - }); - } - - function applyPrerenderedHeadComponent(headElement) { - switch (headElement.type) { - case 'title': - setTitle(headElement.title); - break; - case 'tag': - const tag = createHeadTag(headElement); - prerenderedTags.push(tag); - break; - default: - throw new Error(`Invalid head element type '${headElement.type}'.`); - } - } - - function parseHeadComment(node) { - if (!node || node.nodeType != Node.COMMENT_NODE) { - return; - } - - const commentText = node.textContent; - - if (!commentText) { - return; - } - - const definition = headCommentRegularExpression.exec(commentText); - const json = definition && definition[1]; - - return json && JSON.parse(json); - } - - function removePrerenderedHeadTags() { - prerenderedTags.forEach((tag) => { - tag.remove(); - }); - - prerenderedTags.length = 0; - } - - // Exported functions - - function setTitle(title) { - document.title = title; - } - - function addOrUpdateHeadTag(tag, id) { - removePrerenderedHeadTags(); - removeHeadTag(id); - createHeadTag(tag, id); - } - - function removeHeadTag(id) { - let tag = document.head.querySelector(`[${blazorIdAttributeName}='${id}']`); - tag && tag.remove(); - } - - window._blazorHeadManager = { - setTitle, - addOrUpdateHeadTag, - removeHeadTag, - }; - - resolvePrerenderedHeadComponents(document); -})(); diff --git a/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs index 856740a65f08..d295d6a4a8fe 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs @@ -82,39 +82,6 @@ public void IsCompatibleWithLazyLoadWebAssembly() AssertLogDoesNotContainCriticalMessages("Could not load file or assembly 'Newtonsoft.Json"); } - [Fact] - [QuarantinedTest] - public void CanInfluenceHeadDuringPrerender() - { - Navigate("/prerendered/prerendered-head"); - - // Validate updated head during prerender - Browser.Equal("Initial title", () => Browser.Title); - Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content")); - Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content")); - - BeginInteractivity(); - - // Wait until the component has rerendered - Browser.Exists(By.Id("interactive-indicator")); - - // Validate updated head after prerender - Browser.Equal("Initial title", () => Browser.Title); - Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content")); - Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content")); - - // Change parameter of meta component - var inputMetaBinding = Browser.FindElement(By.Id("input-meta-binding")); - inputMetaBinding.Clear(); - inputMetaBinding.SendKeys("Updated meta content\n"); - - // Validate new meta content attribute - Browser.Equal("Updated meta content", () => GetMetaWithBindings().GetAttribute("content")); - - IWebElement GetMetaWithBindings() => Browser.FindElement(By.Id("meta-with-bindings")); - IWebElement GetMetaWithoutBindings() => Browser.FindElement(By.Id("meta-no-bindings")); - } - [Fact] public void CanReadUrlHashOnlyOnceConnected() { diff --git a/src/Components/test/E2ETest/Tests/HeadComponentsTest.cs b/src/Components/test/E2ETest/Tests/HeadComponentsTest.cs deleted file mode 100644 index b7870b3c657c..000000000000 --- a/src/Components/test/E2ETest/Tests/HeadComponentsTest.cs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Linq; -using BasicTestApp; -using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; -using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; -using Microsoft.AspNetCore.E2ETesting; -using OpenQA.Selenium; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.AspNetCore.Components.E2ETest.Tests -{ - public class HeadComponentsTest : E2ETest.Infrastructure.ServerTestBase> - { - public HeadComponentsTest( - BrowserFixture browserFixture, - ToggleExecutionModeServerFixture serverFixture, - ITestOutputHelper output) - : base(browserFixture, serverFixture, output) - { - } - - protected override void InitializeAsyncCore() - { - Navigate(ServerPathBase, noReload: _serverFixture.ExecutionMode == ExecutionMode.Client); - Browser.MountTestComponent(); - } - - [Fact] - public void Title_DoesChangeDocumentTitle() - { - var titleCount = 3; - var titleButtonsById = Enumerable.Range(0, titleCount) - .Select(i => (i, Browser.FindElement(By.Id($"button-title-{i}")))) - .ToList(); - - Assert.All(titleButtonsById, buttonById => - { - var (id, button) = buttonById; - button.Click(); - - Browser.Equal($"Title {id}", () => Browser.Title); - }); - } - - [Fact] - public void Title_DeepestComponentHasPriority() - { - var nestedTitleButton = Browser.FindElement(By.Id("button-title-nested")); - nestedTitleButton.Click(); - - Browser.Equal("Layer 4", () => Browser.Title); - } - - [Fact] - public void Meta_AddsAndRemovesElements() - { - var metaCount = 3; - var metaButtonsById = Enumerable.Range(0, metaCount) - .Select(i => (i, Browser.FindElement(By.Id($"button-meta-{i}")))) - .ToList(); - - // Validate adding elements - Assert.All(metaButtonsById, buttonById => - { - var (id, button) = buttonById; - button.Click(); - - Browser.Exists(By.Id($"Meta {id}")); - }); - - // Validate removing elements - Assert.All(metaButtonsById, buttonById => - { - var (id, button) = buttonById; - button.Click(); - - Browser.DoesNotExist(By.Id($"Meta {id}")); - }); - } - - [Fact] - public void Meta_UpdatesSameElementWhenComponentPropertyChanged() - { - var metaAttributeInput1 = Browser.FindElement(By.Id("meta-attr-input-1")); - var metaAttributeInput2 = Browser.FindElement(By.Id("meta-attr-input-2")); - var metaElement = FindMetaElement(); - - // Validate initial attribute values - Browser.Equal("First attribute", () => metaElement.GetAttribute("attr1")); - Browser.Equal("Second attribute", () => metaElement.GetAttribute("attr2")); - - // Update the first parameter of the component - metaAttributeInput1.Clear(); - metaAttributeInput1.SendKeys("hello\n"); - metaElement = FindMetaElement(); - - // Validate first attribute updated - Browser.Equal("hello", () => metaElement.GetAttribute("attr1")); - Browser.Equal("Second attribute", () => metaElement.GetAttribute("attr2")); - - // Update the second parameter of the component - metaAttributeInput2.Clear(); - metaAttributeInput2.SendKeys("world\n"); - metaElement = FindMetaElement(); - - // Validate second attribute updated - Browser.Equal("hello", () => metaElement.GetAttribute("attr1")); - Browser.Equal("world", () => metaElement.GetAttribute("attr2")); - - IWebElement FindMetaElement() => Browser.FindElements(By.Id("meta-with-bindings")).Single(); - } - - [Fact] - public void Link_AddsAndRemovesElements() - { - var linkCount = 3; - var linkButtonsById = Enumerable.Range(0, linkCount) - .Select(i => (i, Browser.FindElement(By.Id($"button-link-{i}")))) - .ToList(); - - // Validate adding elements - Assert.All(linkButtonsById, buttonById => - { - var (id, button) = buttonById; - button.Click(); - - Browser.Exists(By.Id($"Link {id}")); - }); - - // Validate removing elements - Assert.All(linkButtonsById, buttonById => - { - var (id, button) = buttonById; - button.Click(); - - Browser.DoesNotExist(By.Id($"Link {id}")); - }); - } - - [Fact] - public void Link_UpdatesSameElementWhenComponentPropertyChanged() - { - var linkAttributeInput1 = Browser.FindElement(By.Id("link-attr-input-1")); - var linkAttributeInput2 = Browser.FindElement(By.Id("link-attr-input-2")); - var linkElement = FindLinkElement(); - - // Validate initial attribute values - Browser.Equal("First attribute", () => linkElement.GetAttribute("attr1")); - Browser.Equal("Second attribute", () => linkElement.GetAttribute("attr2")); - - // Update the first parameter of the component - linkAttributeInput1.Clear(); - linkAttributeInput1.SendKeys("hello\n"); - linkElement = FindLinkElement(); - - // Validate first attribute updated - Browser.Equal("hello", () => linkElement.GetAttribute("attr1")); - Browser.Equal("Second attribute", () => linkElement.GetAttribute("attr2")); - - // Update the second parameter of the component - linkAttributeInput2.Clear(); - linkAttributeInput2.SendKeys("world\n"); - linkElement = FindLinkElement(); - - // Validate second attribute updated - Browser.Equal("hello", () => linkElement.GetAttribute("attr1")); - Browser.Equal("world", () => linkElement.GetAttribute("attr2")); - - IWebElement FindLinkElement() => Browser.FindElements(By.Id("link-with-bindings")).Single(); - } - } -} diff --git a/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj b/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj index f6f34a7e17d3..a610d461f37f 100644 --- a/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj +++ b/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj @@ -18,7 +18,6 @@ - diff --git a/src/Components/test/testassets/BasicTestApp/Index.razor b/src/Components/test/testassets/BasicTestApp/Index.razor index 23d3098bc3b7..dcd7809d0182 100644 --- a/src/Components/test/testassets/BasicTestApp/Index.razor +++ b/src/Components/test/testassets/BasicTestApp/Index.razor @@ -60,7 +60,6 @@ - diff --git a/src/Components/test/testassets/BasicTestApp/ModifyHeadComponent.razor b/src/Components/test/testassets/BasicTestApp/ModifyHeadComponent.razor deleted file mode 100644 index 1242213bb7a1..000000000000 --- a/src/Components/test/testassets/BasicTestApp/ModifyHeadComponent.razor +++ /dev/null @@ -1,119 +0,0 @@ -@using Microsoft.AspNetCore.Components.Web.Extensions.Head - -

- Multiple title elements:
- - @for (int i = 0; i < 3; i++) - { - var titleId = i; - - - - if (selectedTitle == titleId) - { - - } - } -</p> - -<p> - Multiple meta elements:<br /> - - @for (int i = 0; i < metas.Length; i++) - { - var metaId = i; - - <button id="button-meta-@i" @onclick="() => Toggle(metas, metaId)"> - @GetToggleString(metas[metaId]) meta @metaId</button> - - if (metas[metaId]) - { - <Meta id="@($"Meta {metaId}")" /> - } - } -</p> - -<p> - Multiple link elements:<br /> - - @for (int i = 0; i < links.Length; i++) - { - var linkId = i; - - <button id="button-link-@i" @onclick="() => Toggle(links, linkId)"> - @GetToggleString(links[linkId]) link @linkId</button> - - if (links[linkId]) - { - <Link id="@($"Link {linkId}")" /> - } - } -</p> - -<p> - Nested title elements:<br /> - - <button id="button-title-nested" @onclick="() => SetSelectedTitle(3)"> - Nested titles - </button> - - @if (selectedTitle == 3) - { - <div> - <Title Value="Layer 1" /> - <div> - <Title Value="Layer 2" /> - <div> - <Title Value="Layer 3" /> - <div> - <Title Value="Layer 4" /> - </div> - </div> - </div> - </div> - } -</p> - -<p> - Meta elements w/ bindings:<br /> - <input id="meta-attr-input-1" @bind="@metaAttribute1" placeholder="Attribute 1" /><br /> - <input id="meta-attr-input-2" @bind="@metaAttribute2" placeholder="Attribute 2" /><br /> - <Meta id="meta-with-bindings" attr1="@metaAttribute1" attr2="@metaAttribute2" /> -</p> - -<p> - Link elements w/ bindings:<br /> - <input id="link-attr-input-1" @bind="@linkAttribute1" placeholder="Attribute 1" /><br /> - <input id="link-attr-input-2" @bind="@linkAttribute2" placeholder="Attribute 2" /><br /> - <Link id="link-with-bindings" attr1="@linkAttribute1" attr2="@linkAttribute2" /> -</p> - -@code { - private readonly bool[] metas = Enumerable.Repeat(false, 3).ToArray(); - private readonly bool[] links = Enumerable.Repeat(false, 3).ToArray(); - - private int selectedTitle = -1; - - private string metaAttribute1 = "First attribute"; - private string metaAttribute2 = "Second attribute"; - - private string linkAttribute1 = "First attribute"; - private string linkAttribute2 = "Second attribute"; - - private void Toggle(bool[] states, int index) - { - states[index] = !states[index]; - StateHasChanged(); - } - - private void SetSelectedTitle(int title) - { - selectedTitle = title; - StateHasChanged(); - } - - private string GetToggleString(bool b) - => b ? "Disable" : "Enable"; -} diff --git a/src/Components/test/testassets/BasicTestApp/PrerenderedHeadComponent.razor b/src/Components/test/testassets/BasicTestApp/PrerenderedHeadComponent.razor deleted file mode 100644 index 9ced4765eb99..000000000000 --- a/src/Components/test/testassets/BasicTestApp/PrerenderedHeadComponent.razor +++ /dev/null @@ -1,45 +0,0 @@ -@page "/prerendered-head" - -@using Microsoft.AspNetCore.Components.Web.Extensions.Head -@using Microsoft.JSInterop -@inject IJSRuntime JSRuntime - -<p> - This component demonstrates that head components (i.e. Title, Meta, etc.) can take effect during prerendering - and become updatable when the circuit connects. -</p> - -<p> - Title:<br /> - <input id="title-input" @bind="title" placeholder="Set the title" /> - <Title Value=@title /> -</p> - -<p> - Meta:<br /> - <input id="input-meta-binding" @bind="metaContent" placeholder="Set the meta content" /> - <Meta id="meta-with-bindings" content="@metaContent" /> -</p> - -<Meta id="meta-no-bindings" content="Immutable meta content" /> - -@if (isInteractive) -{ - <span id="interactive-indicator">Interactive mode enabled.</span> -} - -@code { - private string title = "Initial title"; - private string metaContent = "Initial meta content"; - - private bool isInteractive; - - protected override void OnAfterRender(bool firstRender) - { - if (firstRender) - { - isInteractive = true; - StateHasChanged(); - } - } -} diff --git a/src/Components/test/testassets/BasicTestApp/Program.cs b/src/Components/test/testassets/BasicTestApp/Program.cs index 0a33c288da0d..c3be8fafd7f1 100644 --- a/src/Components/test/testassets/BasicTestApp/Program.cs +++ b/src/Components/test/testassets/BasicTestApp/Program.cs @@ -4,18 +4,15 @@ using System; using System.Globalization; using System.Net.Http; -using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Web; using BasicTestApp.AuthTest; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Components.Web.Extensions; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.AspNetCore.Components.WebAssembly.Http; using Microsoft.AspNetCore.Components.WebAssembly.Services; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Configuration; using Microsoft.JSInterop;