Files
outline/app/editor/components/EmojiMenu.tsx
T
Tom MoorandClaude Fable 5 b17f2611bf chore: React 18 upgrade (#13559)
* React 18 upgrade

* fix: Force synchronous React rendering in server HTML export

React 18 can defer a legacy ReactDOM.render commit when sync work is
queued, leaving exported component nodes empty. Wrap the render in
flushSync, and flush unmount-scheduled passive effects before global
env cleanup so React never runs without a window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* refactor: Move server ComponentView to createRoot

ReactDOM.render and unmountComponentAtNode are removed in React 19.
flushSync around root.render keeps the mount synchronous for the
HTML-export path, which reads the DOM immediately after.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Enable CI

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-03 01:43:47 -04:00

82 lines
2.2 KiB
TypeScript

import { capitalize } from "es-toolkit/compat";
import { observer } from "mobx-react";
import { useCallback, useMemo, useEffect } from "react";
import { emojiMartToGemoji, snakeCase } from "@shared/editor/lib/emoji";
import { search as emojiSearch } from "@shared/utils/emoji";
import EmojiMenuItem from "./EmojiMenuItem";
import type { Props as SuggestionsMenuProps } from "./SuggestionsMenu";
import SuggestionsMenu from "./SuggestionsMenu";
import useStores from "~/hooks/useStores";
import { determineIconType } from "@shared/utils/icon";
import { IconType } from "@shared/types";
type Emoji = {
name: string;
title: string;
emoji: string;
description: string;
attrs: { "data-name": string };
};
type Props = Omit<
SuggestionsMenuProps<Emoji>,
"renderMenuItem" | "items" | "embeds"
>;
const EmojiMenu = (props: Props) => {
const { emojis } = useStores();
const { search = "" } = props;
useEffect(() => {
if (search) {
void emojis.fetchPage({ query: search });
}
}, [emojis, search]);
const items = useMemo(
() =>
emojiSearch({ customEmojis: emojis.orderedData, query: search })
.map((item) => {
// We snake_case the shortcode for backwards compatability with gemoji to
// avoid multiple formats being written into documents.
const id = emojiMartToGemoji[item.id] || item.id;
const type = determineIconType(id);
const value = type === IconType.Custom ? id : snakeCase(id);
const emoji = item.value;
return {
name: "emoji",
title: emoji,
description:
type === IconType.Custom
? item.name
: capitalize(item.name.toLowerCase()),
emoji,
attrs: { "data-name": value },
};
})
.slice(0, 15),
[search, emojis.orderedData]
);
const renderMenuItem = useCallback<
SuggestionsMenuProps<Emoji>["renderMenuItem"]
>(
(item, _index, options) => (
<EmojiMenuItem {...options} title={item.description} emoji={item.emoji} />
),
[]
);
return (
<SuggestionsMenu
{...props}
filterable={false}
renderMenuItem={renderMenuItem}
items={items}
/>
);
};
export default observer(EmojiMenu);