Skip to content

Commit 7c78467

Browse files
Fix broken title updating in web app (#3253)
React can hoist the title tag, but apparently this feature is missing from Preact.
1 parent 330032d commit 7c78467

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/app-web/src/Cheatsheet.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Cheatsheet as OriginalCheatsheet } from "@cursorless/lib-cheatsheet";
22
import defaultCheatsheetInfo from "@cursorless/lib-cheatsheet/defaultSpokenForms";
3+
import { Title } from "./Title";
34

45
export function Cheatsheet() {
56
return (
67
<>
7-
<title>Cursorless cheatsheet</title>
8+
<Title>Cursorless cheatsheet</Title>
89
<OriginalCheatsheet cheatsheetInfo={defaultCheatsheetInfo} />
910
</>
1011
);

packages/app-web/src/LandingPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Button } from "./Button";
22
import { EmbeddedVideo } from "./EmbeddedVideo";
3+
import { Title } from "./Title";
34
import { DESCRIPTION, NAME, TITLE, YOUTUBE_SLUG } from "./constants";
45
import Logo from "./logo.svg?react";
56

67
export function LandingPage() {
78
return (
89
<>
9-
<title>{TITLE}</title>
10+
<Title>{TITLE}</Title>
1011

1112
<main className="landing-page">
1213
<div className="container">

packages/app-web/src/Title.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useEffect } from "preact/hooks";
2+
3+
interface Props {
4+
children: string;
5+
}
6+
7+
export function Title({ children }: Props) {
8+
useEffect(() => {
9+
if (children !== document.title) {
10+
document.title = children;
11+
}
12+
}, [children]);
13+
14+
return null;
15+
}

0 commit comments

Comments
 (0)