Skip to content
代码片段 群组 项目
未验证 提交 7209d49c 编辑于 作者: Mackinnon Buck's avatar Mackinnon Buck 提交者: GitHub
浏览文件

[release/6.0] Backport 'Make title prerendering not interfere with svg titles' (#44343)


* Make title prerendering not interfere with svg titles. Fixes #36380. (#37009)

* Update blazor.*.js

Co-authored-by: default avatarSteve Sanderson <SteveSandersonMS@users.noreply.github.com>
上级 538d9025
No related branches found
No related tags found
无相关合并请求
文件被 .gitattributes 条目压制或文件的编码不受支持。
文件被 .gitattributes 条目压制或文件的编码不受支持。
...@@ -5,7 +5,8 @@ export const PageTitle = { ...@@ -5,7 +5,8 @@ export const PageTitle = {
}; };
function getAndRemoveExistingTitle(): string | null { function getAndRemoveExistingTitle(): string | null {
const titleElements = document.getElementsByTagName('title'); // Other <title> elements may exist outside <head> (e.g., inside <svg> elements) but they aren't page titles
const titleElements = document.head ? document.head.getElementsByTagName('title') : [];
if (titleElements.length === 0) { if (titleElements.length === 0) {
return null; return null;
......
...@@ -36,6 +36,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests ...@@ -36,6 +36,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
Browser.Equal("Title 1", () => Browser.Title); Browser.Equal("Title 1", () => Browser.Title);
Browser.Exists(By.Id("meta-description")); Browser.Exists(By.Id("meta-description"));
// Check that unrelated <title> elements were left alone
Browser.Equal("This element is used to test that PageTitle prerendering doesn't interfere with non-head title elements.",
() => Browser.Exists(By.CssSelector("#svg-for-title-prerendering-test title")).Text);
var titleText1 = Browser.FindElement(By.Id("title-text-1")); var titleText1 = Browser.FindElement(By.Id("title-text-1"));
titleText1.Clear(); titleText1.Clear();
titleText1.SendKeys("Updated title 1\n"); titleText1.SendKeys("Updated title 1\n");
......
...@@ -34,5 +34,11 @@ ...@@ -34,5 +34,11 @@
}); });
} }
</script> </script>
<svg id="svg-for-title-prerendering-test" viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg" style="width: 1px; height: 1px;">
<rect x="11" y="1" width="8" height="8">
<title>This element is used to test that PageTitle prerendering doesn't interfere with non-head title elements.</title>
</rect>
</svg>
</body> </body>
</html> </html>
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册