diff --git a/app/javascript/mastodon/components/autosuggest_emoji.tsx b/app/javascript/mastodon/components/autosuggest_emoji.tsx
index 9111bb3368..ff591fe3d9 100644
--- a/app/javascript/mastodon/components/autosuggest_emoji.tsx
+++ b/app/javascript/mastodon/components/autosuggest_emoji.tsx
@@ -1,7 +1,5 @@
import type { FC } from 'react';
-import { useCustomEmojis } from '@/mastodon/hooks/useCustomEmojis';
-
import { Emoji } from './emoji';
interface LegacyEmoji {
@@ -12,11 +10,10 @@ interface LegacyEmoji {
}
export const AutosuggestEmoji: FC<{ emoji: LegacyEmoji }> = ({ emoji }) => {
- const emojis = useCustomEmojis();
const colons = `:${emoji.id}:`;
return (
);
diff --git a/app/javascript/mastodon/components/autosuggest_input.jsx b/app/javascript/mastodon/components/autosuggest_input.jsx
index 445ec601cf..4a3b7d9040 100644
--- a/app/javascript/mastodon/components/autosuggest_input.jsx
+++ b/app/javascript/mastodon/components/autosuggest_input.jsx
@@ -11,6 +11,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg
import { AutosuggestEmoji } from './autosuggest_emoji';
import { AutosuggestHashtag } from './autosuggest_hashtag';
+import { LocalCustomEmojiProvider } from './emoji/context';
const textAtCursorMatchesToken = (str, caretPosition, searchTokens) => {
let word;
@@ -219,15 +220,17 @@ export default class AutosuggestInput extends ImmutablePureComponent {
spellCheck={spellCheck}
/>
-
- {({ props }) => (
-
-
- {suggestions.map(this.renderSuggestion)}
+
+
+ {({ props }) => (
+
+
+ {suggestions.map(this.renderSuggestion)}
+
-
- )}
-
+ )}
+
+
);
}
diff --git a/app/javascript/mastodon/components/autosuggest_textarea.jsx b/app/javascript/mastodon/components/autosuggest_textarea.jsx
index 9b01d300a3..fb99f62a73 100644
--- a/app/javascript/mastodon/components/autosuggest_textarea.jsx
+++ b/app/javascript/mastodon/components/autosuggest_textarea.jsx
@@ -12,6 +12,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg
import { AutosuggestEmoji } from './autosuggest_emoji';
import { AutosuggestHashtag } from './autosuggest_hashtag';
+import { LocalCustomEmojiProvider } from './emoji/context';
const textAtCursorMatchesToken = (str, caretPosition) => {
let word;
@@ -218,15 +219,17 @@ const AutosuggestTextarea = forwardRef(({
lang={lang}
/>
-
- {({ props }) => (
-
-
- {suggestions.map(renderSuggestion)}
+
+
+ {({ props }) => (
+
+
+ {suggestions.map(renderSuggestion)}
+
-
- )}
-
+ )}
+
+
);
});
diff --git a/app/javascript/mastodon/components/emoji/context.tsx b/app/javascript/mastodon/components/emoji/context.tsx
index ceed1d1ff6..b4a364df87 100644
--- a/app/javascript/mastodon/components/emoji/context.tsx
+++ b/app/javascript/mastodon/components/emoji/context.tsx
@@ -1,4 +1,9 @@
-import type { MouseEventHandler, PropsWithChildren } from 'react';
+import type {
+ FC,
+ MouseEventHandler,
+ PropsWithChildren,
+ ReactNode,
+} from 'react';
import {
createContext,
useCallback,
@@ -8,6 +13,7 @@ import {
} from 'react';
import { cleanExtraEmojis } from '@/mastodon/features/emoji/normalize';
+import { useCustomEmojis } from '@/mastodon/hooks/useCustomEmojis';
import { autoPlayGif } from '@/mastodon/initial_state';
import { polymorphicForwardRef } from '@/types/polymorphic';
import type {
@@ -103,3 +109,10 @@ export const CustomEmojiProvider = ({
);
};
+
+export const LocalCustomEmojiProvider: FC<{ children: ReactNode }> = ({
+ children,
+}) => {
+ const emojis = useCustomEmojis();
+ return {children};
+};
diff --git a/app/javascript/mastodon/components/emoji/index.tsx b/app/javascript/mastodon/components/emoji/index.tsx
index 3989b595d7..9b917df6ea 100644
--- a/app/javascript/mastodon/components/emoji/index.tsx
+++ b/app/javascript/mastodon/components/emoji/index.tsx
@@ -19,7 +19,6 @@ import {
stringToEmojiState,
tokenizeText,
} from '@/mastodon/features/emoji/render';
-import type { ExtraCustomEmojiMap } from '@/mastodon/features/emoji/types';
import { AnimateEmojiContext, CustomEmojiContext } from './context';
@@ -27,19 +26,14 @@ interface EmojiProps {
code: string;
showFallback?: boolean;
showLoading?: boolean;
- customEmoji?: ExtraCustomEmojiMap | null;
}
export const Emoji: FC = ({
code,
showFallback = true,
showLoading = true,
- customEmoji: customEmojiOverride,
}) => {
- let customEmoji = useContext(CustomEmojiContext);
- if (customEmojiOverride) {
- customEmoji = customEmojiOverride;
- }
+ const customEmoji = useContext(CustomEmojiContext);
// First, set the emoji state based on the input code.
const [state, setState] = useState(() =>
diff --git a/app/javascript/mastodon/hooks/useCustomEmojis.ts b/app/javascript/mastodon/hooks/useCustomEmojis.ts
index 4bac1cef2e..aeb77620dd 100644
--- a/app/javascript/mastodon/hooks/useCustomEmojis.ts
+++ b/app/javascript/mastodon/hooks/useCustomEmojis.ts
@@ -1,9 +1,12 @@
import { useEffect, useState } from 'react';
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
+import { emojiLogger } from '../features/emoji/utils';
let emojis: ExtraCustomEmojiMap | null = null;
+const log = emojiLogger('useCustomEmojis');
+
export function useCustomEmojis() {
const [, setLoaded] = useState(emojis !== null);
useEffect(() => {
@@ -21,6 +24,7 @@ async function loadEmojisIntoCache() {
const { loadAllCustomEmoji } = await import('../features/emoji/database');
const emojisRaw = await loadAllCustomEmoji();
if (emojisRaw === null) {
+ log('Custom emojis not loaded yet');
return;
}
@@ -32,4 +36,5 @@ async function loadEmojisIntoCache() {
static_url: emoji.static_url,
};
}
+ log('Loaded %d custom emojis into cache', Object.keys(emojis).length);
}