Unblock React Compiler for 23 components across ten small causes (#11542)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tomasz Zawadzki
2026-08-31 15:49:57 +02:00
committed by GitHub
parent 8bf5696d3c
commit f9cf58ea44
27 changed files with 201 additions and 148 deletions
+10 -4
View File
@@ -1,14 +1,20 @@
import {useEffect, useState} from 'react'
import type tldts from 'tldts'
/**
* Module scope because React Compiler cannot lower an `import()` expression
* inside a component or hook body.
*/
function loadTLDs(): Promise<typeof tldts> {
// @ts-expect-error - valid path
return import('tldts/dist/index.cjs.min.js')
}
export function useTLDs() {
const [tlds, setTlds] = useState<typeof tldts>()
useEffect(() => {
// @ts-expect-error - valid path
import('tldts/dist/index.cjs.min.js').then(tlds => {
setTlds(tlds)
})
loadTLDs().then(setTlds)
}, [])
return tlds
+11 -2
View File
@@ -29,6 +29,16 @@ const E_SAME_AS_SOURCE_LANGUAGE =
const E_EMPTY_RESULT = 'Translation result is empty.'
const E_INVALID_SOURCE_LANGUAGE = 'Invalid source language'
/**
* Returns a copy of `obj` without `key`. A computed property in a destructuring
* pattern is syntax React Compiler cannot lower, so this stays out of the hook.
*/
function omitKey<T extends Record<string, unknown>>(obj: T, key: string): T {
const next = {...obj}
delete next[key]
return next
}
/**
* Attempts on-device translation via @bsky.app/expo-translate-text.
* Uses a lazy import to avoid crashing if the native module isn't linked into
@@ -199,8 +209,7 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
setRefCounts(prev => {
const newCount = (prev[key] ?? 1) - 1
if (newCount <= 0) {
const {[key]: _, ...rest} = prev
return rest
return omitKey(prev, key)
}
return {...prev, [key]: newCount}
})
+3 -1
View File
@@ -6,7 +6,9 @@ let emojis: Awaited<ReturnType<typeof getEmojis>> | null = null
export function useGetEmojis() {
return useCallback(async () => {
emojis ??= await getEmojis()
if (emojis == null) {
emojis = await getEmojis()
}
return emojis
}, [])
}