Skip to content

Commit

Permalink
🐛 fix: Turn off revalidateOnFocus in swr
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 1, 2023
1 parent e1fc9c3 commit bb0fcef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/EmojiPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const EmojiPicker = memo<EmojiPickerProps>(
const { data: i18n } = useSWR(
locale,
async () => await import(`@emoji-mart/data/i18n/${locale.split('-')[0]}.json`),
{ revalidateOnFocus: false },
);

const [ava, setAva] = useMergeState('🤖', {
Expand Down
30 changes: 17 additions & 13 deletions src/hooks/useHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ const initHighlighter = async (lang: string): Promise<Highlighter> => {
};

export const useHighlight = (text: string, lang: string, isDarkMode: boolean) =>
useSWR([lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'), async () => {
try {
const language = lang.toLowerCase();
const highlighter = await initHighlighter(language);
const html = highlighter?.codeToHtml(text, {
lang: languageMap.includes(language as any) ? language : FALLBACK_LANG,
theme: isDarkMode ? 'dark' : 'light',
});
return html;
} catch {
return `<pre><code>${text}</code></pre>`;
}
});
useSWR(
[lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'),
async () => {
try {
const language = lang.toLowerCase();
const highlighter = await initHighlighter(language);
const html = highlighter?.codeToHtml(text, {
lang: languageMap.includes(language as any) ? language : FALLBACK_LANG,
theme: isDarkMode ? 'dark' : 'light',
});
return html;
} catch {
return `<pre><code>${text}</code></pre>`;
}
},
{ revalidateOnFocus: false },
);

export { default as languageMap } from './languageMap';

0 comments on commit bb0fcef

Please sign in to comment.