Unblock React Compiler for 23 components across ten small causes
Each is a self-contained rewrite of syntax React Compiler cannot lower: - `??=` -> an explicit null check - dynamic `import()` -> a module-scope loader - complex default parameter values -> module-scope consts - reassigned destructured parameters -> locals - functions used above their own declaration -> reordered - counters mutated inside a callback -> loop index or a local object - optional chains in a ternary test -> a hoisted const - a computed key in a destructuring pattern -> an omitKey helper - manual useMemo/useCallback the compiler cannot preserve -> deleted - exhaustive-deps suppressions -> useEffectEvent Skipped components: 125 -> 102. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {useCallback, useEffect} from 'react'
|
import {useCallback, useEffect, useEffectEvent} from 'react'
|
||||||
import {ScrollView, View} from 'react-native'
|
import {ScrollView, View} from 'react-native'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import {Trans, useLingui} from '@lingui/react/macro'
|
import {Trans, useLingui} from '@lingui/react/macro'
|
||||||
@@ -76,7 +76,7 @@ export function NoAccessScreen() {
|
|||||||
const geolocationString = createGeolocationString(geolocation, i18n.locale)
|
const geolocationString = createGeolocationString(geolocation, i18n.locale)
|
||||||
const isUsingGPS = !!geolocation.deviceGeolocation?.countryCode && IS_NATIVE
|
const isUsingGPS = !!geolocation.deviceGeolocation?.countryCode && IS_NATIVE
|
||||||
|
|
||||||
useEffect(() => {
|
const onShown = useEffectEvent(() => {
|
||||||
// just counting overall hits here
|
// just counting overall hits here
|
||||||
ax.metric(`blockedGeoOverlay:shown`, {})
|
ax.metric(`blockedGeoOverlay:shown`, {})
|
||||||
ax.metric(`ageAssurance:noAccessScreen:shown`, {
|
ax.metric(`ageAssurance:noAccessScreen:shown`, {
|
||||||
@@ -85,8 +85,10 @@ export function NoAccessScreen() {
|
|||||||
hasDeclaredAge,
|
hasDeclaredAge,
|
||||||
canUpdateBirthday,
|
canUpdateBirthday,
|
||||||
})
|
})
|
||||||
// TODO This can be cleaned up with useEffectEvent once we're on 19.2
|
})
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
|
useEffect(() => {
|
||||||
|
onShown()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onPressLogout = useCallback(() => {
|
const onPressLogout = useCallback(() => {
|
||||||
|
|||||||
+15
-14
@@ -1,5 +1,3 @@
|
|||||||
import {useMemo} from 'react'
|
|
||||||
|
|
||||||
import {type Breakpoint, useBreakpoints} from '#/alf/breakpoints'
|
import {type Breakpoint, useBreakpoints} from '#/alf/breakpoints'
|
||||||
import * as tokens from '#/alf/tokens'
|
import * as tokens from '#/alf/tokens'
|
||||||
|
|
||||||
@@ -44,23 +42,26 @@ export function useGutters([top, right, bottom, left]: [
|
|||||||
Gutter,
|
Gutter,
|
||||||
Gutter,
|
Gutter,
|
||||||
]): Gutters
|
]): Gutters
|
||||||
export function useGutters([top, right, bottom, left]: Gutter[]) {
|
export function useGutters(gutter: Gutter[]) {
|
||||||
const {activeBreakpoint} = useBreakpoints()
|
const {activeBreakpoint} = useBreakpoints()
|
||||||
|
/*
|
||||||
|
* Destructured in the body rather than the parameter list: these are
|
||||||
|
* reassigned below to fill in the CSS-shorthand forms, and React Compiler
|
||||||
|
* cannot lower a reassigned destructured parameter.
|
||||||
|
*/
|
||||||
|
let [top, right, bottom, left] = gutter
|
||||||
if (right === undefined) {
|
if (right === undefined) {
|
||||||
right = bottom = left = top
|
right = bottom = left = top
|
||||||
} else if (bottom === undefined) {
|
} else if (bottom === undefined) {
|
||||||
bottom = top
|
bottom = top
|
||||||
left = right
|
left = right
|
||||||
}
|
}
|
||||||
return useMemo(() => {
|
return {
|
||||||
return {
|
paddingTop: top === 0 ? 0 : gutters[top][activeBreakpoint || 'default'],
|
||||||
paddingTop: top === 0 ? 0 : gutters[top][activeBreakpoint || 'default'],
|
paddingRight:
|
||||||
paddingRight:
|
right === 0 ? 0 : gutters[right][activeBreakpoint || 'default'],
|
||||||
right === 0 ? 0 : gutters[right][activeBreakpoint || 'default'],
|
paddingBottom:
|
||||||
paddingBottom:
|
bottom === 0 ? 0 : gutters[bottom][activeBreakpoint || 'default'],
|
||||||
bottom === 0 ? 0 : gutters[bottom][activeBreakpoint || 'default'],
|
paddingLeft: left === 0 ? 0 : gutters[left][activeBreakpoint || 'default'],
|
||||||
paddingLeft:
|
}
|
||||||
left === 0 ? 0 : gutters[left][activeBreakpoint || 'default'],
|
|
||||||
}
|
|
||||||
}, [activeBreakpoint, top, right, bottom, left])
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export function useDialogControl(): DialogOuterProps['control'] {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
activeDialogs.current.set(id, control)
|
activeDialogs.current.set(id, control)
|
||||||
return () => {
|
return () => {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
activeDialogs.current.delete(id)
|
activeDialogs.current.delete(id)
|
||||||
}
|
}
|
||||||
}, [id, activeDialogs])
|
}, [id, activeDialogs])
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {useCallback} from 'react'
|
|
||||||
import {init} from 'emoji-mart'
|
import {init} from 'emoji-mart'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,15 +15,16 @@ let loadRequested = false
|
|||||||
*
|
*
|
||||||
* @see {@link https://github.com/missive/emoji-mart/blob/16978d04a766eec6455e2e8bb21cd8dc0b3c7436/README.md?plain=1#L194 | emoji-mart preloading docs}
|
* @see {@link https://github.com/missive/emoji-mart/blob/16978d04a766eec6455e2e8bb21cd8dc0b3c7436/README.md?plain=1#L194 | emoji-mart preloading docs}
|
||||||
*/
|
*/
|
||||||
export function useWebPreloadEmoji({immediate}: {immediate?: boolean} = {}) {
|
async function loadEmojiData() {
|
||||||
const preload = useCallback(async () => {
|
if (loadRequested) return
|
||||||
if (loadRequested) return
|
loadRequested = true
|
||||||
loadRequested = true
|
try {
|
||||||
try {
|
const data = (await import('@emoji-mart/data')).default
|
||||||
const data = (await import('@emoji-mart/data')).default
|
init({data})
|
||||||
init({data})
|
} catch (e) {}
|
||||||
} catch (e) {}
|
}
|
||||||
}, [])
|
|
||||||
if (immediate) preload()
|
export function useWebPreloadEmoji({immediate}: {immediate?: boolean} = {}) {
|
||||||
return preload
|
if (immediate) loadEmojiData()
|
||||||
|
return loadEmojiData
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,16 @@ export function InterestTabs({
|
|||||||
const pendingTabOffsets = useRef<{x: number; width: number}[]>([])
|
const pendingTabOffsets = useRef<{x: number; width: number}[]>([])
|
||||||
const [tabOffsets, setTabOffsets] = useState<{x: number; width: number}[]>([])
|
const [tabOffsets, setTabOffsets] = useState<{x: number; width: number}[]>([])
|
||||||
|
|
||||||
|
function scrollIntoViewIfNeeded(index: number) {
|
||||||
|
const btnLayout = tabOffsets[index]
|
||||||
|
if (!btnLayout) return
|
||||||
|
listRef.current?.scrollTo({
|
||||||
|
// centered
|
||||||
|
x: btnLayout.x - (totalWidth / 2 - btnLayout.width / 2),
|
||||||
|
animated: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const onInitialLayout = useNonReactiveCallback(() => {
|
const onInitialLayout = useNonReactiveCallback(() => {
|
||||||
const index = interests.indexOf(selectedInterest)
|
const index = interests.indexOf(selectedInterest)
|
||||||
scrollIntoViewIfNeeded(index)
|
scrollIntoViewIfNeeded(index)
|
||||||
@@ -65,16 +75,6 @@ export function InterestTabs({
|
|||||||
}
|
}
|
||||||
}, [tabOffsets, onInitialLayout])
|
}, [tabOffsets, onInitialLayout])
|
||||||
|
|
||||||
function scrollIntoViewIfNeeded(index: number) {
|
|
||||||
const btnLayout = tabOffsets[index]
|
|
||||||
if (!btnLayout) return
|
|
||||||
listRef.current?.scrollTo({
|
|
||||||
// centered
|
|
||||||
x: btnLayout.x - (totalWidth / 2 - btnLayout.width / 2),
|
|
||||||
animated: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSelectTab(index: number) {
|
function handleSelectTab(index: number) {
|
||||||
const tab = interests[index]
|
const tab = interests[index]
|
||||||
onSelectTab(tab)
|
onSelectTab(tab)
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
|||||||
import {APP_LANGUAGES} from '#/locale/languages'
|
import {APP_LANGUAGES} from '#/locale/languages'
|
||||||
import * as Select from '#/components/Select'
|
import * as Select from '#/components/Select'
|
||||||
|
|
||||||
|
const DEFAULT_ITEMS = APP_LANGUAGES.map(l => ({
|
||||||
|
label: l.name,
|
||||||
|
value: l.code2,
|
||||||
|
}))
|
||||||
|
|
||||||
export function LanguageSelect({
|
export function LanguageSelect({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
items = APP_LANGUAGES.map(l => ({
|
items = DEFAULT_ITEMS,
|
||||||
label: l.name,
|
|
||||||
value: l.code2,
|
|
||||||
})),
|
|
||||||
label,
|
label,
|
||||||
disabledBlueskySupportedLanguageSanitization = false,
|
disabledBlueskySupportedLanguageSanitization = false,
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@@ -79,6 +79,11 @@ const ImageItem = ({
|
|||||||
|
|
||||||
// Keep track of when we're entering or leaving scaled rendering.
|
// Keep track of when we're entering or leaving scaled rendering.
|
||||||
// Note: DO NOT move any logic reading animated values outside this function.
|
// Note: DO NOT move any logic reading animated values outside this function.
|
||||||
|
function handleZoom(nextIsScaled: boolean) {
|
||||||
|
setIsScaled(nextIsScaled)
|
||||||
|
onZoom(nextIsScaled)
|
||||||
|
}
|
||||||
|
|
||||||
useAnimatedReaction(
|
useAnimatedReaction(
|
||||||
() => {
|
() => {
|
||||||
if (pinchScale.get() !== 1) {
|
if (pinchScale.get() !== 1) {
|
||||||
@@ -100,11 +105,6 @@ const ImageItem = ({
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
function handleZoom(nextIsScaled: boolean) {
|
|
||||||
setIsScaled(nextIsScaled)
|
|
||||||
onZoom(nextIsScaled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// On Android, stock apps prevent going "out of bounds" on pan or pinch. You should "bump" into edges.
|
// On Android, stock apps prevent going "out of bounds" on pan or pinch. You should "bump" into edges.
|
||||||
// If the user tried to pan too hard, this function will provide the negative panning to stay in bounds.
|
// If the user tried to pan too hard, this function will provide the negative panning to stay in bounds.
|
||||||
function getExtraTranslationToStayInBounds(
|
function getExtraTranslationToStayInBounds(
|
||||||
|
|||||||
@@ -121,10 +121,12 @@ function InnerWrapper({embed}: Props) {
|
|||||||
setIsActive={active => {
|
setIsActive={active => {
|
||||||
setIsActive(active)
|
setIsActive(active)
|
||||||
if (active) {
|
if (active) {
|
||||||
telemetryRef.current ??= createPlaybackTelemetry({
|
if (telemetryRef.current == null) {
|
||||||
surface: 'feed',
|
telemetryRef.current = createPlaybackTelemetry({
|
||||||
presentation: embed.presentation === 'gif' ? 'gif' : 'video',
|
surface: 'feed',
|
||||||
})
|
presentation: embed.presentation === 'gif' ? 'gif' : 'video',
|
||||||
|
})
|
||||||
|
}
|
||||||
telemetryRef.current.activated()
|
telemetryRef.current.activated()
|
||||||
} else {
|
} else {
|
||||||
telemetryRef.current?.deactivated()
|
telemetryRef.current?.deactivated()
|
||||||
|
|||||||
@@ -86,17 +86,20 @@ export function ProfileBadges({
|
|||||||
|
|
||||||
const gap = isOnTheSmallSide ? a.gap_2xs : a.gap_xs
|
const gap = isOnTheSmallSide ? a.gap_2xs : a.gap_xs
|
||||||
const padding = gap.gap / 2
|
const padding = gap.gap / 2
|
||||||
|
const hitSlops = []
|
||||||
let visibleBadgeIndex = 0
|
let visibleBadgeIndex = 0
|
||||||
const hitSlops = badgeVisibility.map(isVisible => {
|
for (const isVisible of badgeVisibility) {
|
||||||
if (!isVisible) return HITSLOP_20
|
if (!isVisible) {
|
||||||
|
hitSlops.push(HITSLOP_20)
|
||||||
|
continue
|
||||||
|
}
|
||||||
const index = visibleBadgeIndex++
|
const index = visibleBadgeIndex++
|
||||||
return {
|
hitSlops.push({
|
||||||
...HITSLOP_20,
|
...HITSLOP_20,
|
||||||
left: index === 0 ? HITSLOP_20.left : padding,
|
left: index === 0 ? HITSLOP_20.left : padding,
|
||||||
right: index === badgeCount - 1 ? HITSLOP_20.right : padding,
|
right: index === badgeCount - 1 ? HITSLOP_20.right : padding,
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.flex_row, a.align_center, gap, style]}>
|
<View style={[a.flex_row, a.align_center, gap, style]}>
|
||||||
|
|||||||
@@ -122,9 +122,12 @@ export function Trigger({children, hitSlop, label}: TriggerProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultValueText: NonNullable<ValueProps['children']> = value =>
|
||||||
|
value.label
|
||||||
|
|
||||||
export function ValueText({
|
export function ValueText({
|
||||||
placeholder,
|
placeholder,
|
||||||
children = value => value.label,
|
children = defaultValueText,
|
||||||
style,
|
style,
|
||||||
}: ValueProps) {
|
}: ValueProps) {
|
||||||
const [value] = useContext(ValueTextContext)
|
const [value] = useContext(ValueTextContext)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export function Card({
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
const isOwnStarterPack = creator?.did === currentAccount?.did
|
||||||
|
|
||||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||||
return null
|
return null
|
||||||
@@ -82,7 +83,7 @@ export function Card({
|
|||||||
emoji
|
emoji
|
||||||
style={[a.leading_snug, t.atoms.text_contrast_medium]}
|
style={[a.leading_snug, t.atoms.text_contrast_medium]}
|
||||||
numberOfLines={1}>
|
numberOfLines={1}>
|
||||||
{creator?.did === currentAccount?.did
|
{isOwnStarterPack
|
||||||
? _(msg`Starter pack by you`)
|
? _(msg`Starter pack by you`)
|
||||||
: _(msg`Starter pack by ${sanitizeHandle(creator.handle, '@')}`)}
|
: _(msg`Starter pack by ${sanitizeHandle(creator.handle, '@')}`)}
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useEffectEvent, useState} from 'react'
|
||||||
import {Pressable, View} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
import {ImageBackground} from 'expo-image'
|
import {ImageBackground} from 'expo-image'
|
||||||
import {Trans, useLingui} from '@lingui/react/macro'
|
import {Trans, useLingui} from '@lingui/react/macro'
|
||||||
@@ -35,11 +35,14 @@ export function WelcomeModal({control}: WelcomeModalProps) {
|
|||||||
}, 150)
|
}, 150)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onPresented = useEffectEvent(() => {
|
||||||
|
ax.metric('welcomeModal:presented', {})
|
||||||
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (control.isOpen) {
|
if (control.isOpen) {
|
||||||
ax.metric('welcomeModal:presented', {})
|
onPresented()
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [control.isOpen])
|
}, [control.isOpen])
|
||||||
|
|
||||||
const onPressCreateAccount = () => {
|
const onPressCreateAccount = () => {
|
||||||
|
|||||||
@@ -295,6 +295,37 @@ export function PostInteractionSettingsDialogControlledInner(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lives outside the component because the early `return []` inside a `useMemo`
|
||||||
|
* is memoization React Compiler cannot preserve.
|
||||||
|
*/
|
||||||
|
function getToggleGroupValues(settings: ThreadgateAllowUISetting[]): string[] {
|
||||||
|
const values: string[] = []
|
||||||
|
for (const setting of settings) {
|
||||||
|
switch (setting.type) {
|
||||||
|
case 'everybody':
|
||||||
|
case 'nobody':
|
||||||
|
// no granularity, early return with nothing
|
||||||
|
return []
|
||||||
|
case 'followers':
|
||||||
|
values.push('followers')
|
||||||
|
break
|
||||||
|
case 'following':
|
||||||
|
values.push('following')
|
||||||
|
break
|
||||||
|
case 'mention':
|
||||||
|
values.push('mention')
|
||||||
|
break
|
||||||
|
case 'list':
|
||||||
|
values.push(`list:${setting.list}`)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
export function PostInteractionSettingsForm({
|
export function PostInteractionSettingsForm({
|
||||||
canSave = true,
|
canSave = true,
|
||||||
onSave,
|
onSave,
|
||||||
@@ -349,32 +380,7 @@ export function PostInteractionSettingsForm({
|
|||||||
v => v.type === 'list',
|
v => v.type === 'list',
|
||||||
).length
|
).length
|
||||||
|
|
||||||
const toggleGroupValues = useMemo(() => {
|
const toggleGroupValues = getToggleGroupValues(threadgateAllowUISettings)
|
||||||
const values: string[] = []
|
|
||||||
for (const setting of threadgateAllowUISettings) {
|
|
||||||
switch (setting.type) {
|
|
||||||
case 'everybody':
|
|
||||||
case 'nobody':
|
|
||||||
// no granularity, early return with nothing
|
|
||||||
return []
|
|
||||||
case 'followers':
|
|
||||||
values.push('followers')
|
|
||||||
break
|
|
||||||
case 'following':
|
|
||||||
values.push('following')
|
|
||||||
break
|
|
||||||
case 'mention':
|
|
||||||
values.push('mention')
|
|
||||||
break
|
|
||||||
case 'list':
|
|
||||||
values.push(`list:${setting.list}`)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}, [threadgateAllowUISettings])
|
|
||||||
|
|
||||||
const toggleGroupOnChange = (values: string[]) => {
|
const toggleGroupOnChange = (values: string[]) => {
|
||||||
const settings: ThreadgateAllowUISetting[] = []
|
const settings: ThreadgateAllowUISetting[] = []
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export function ReportDialog(
|
|||||||
openCount: number
|
openCount: number
|
||||||
videoTimestampSeconds?: number
|
videoTimestampSeconds?: number
|
||||||
}>({openCount: 0})
|
}>({openCount: 0})
|
||||||
const onOpen = useCallback(() => {
|
const onOpen = () => {
|
||||||
const seconds =
|
const seconds =
|
||||||
subject?.type === 'post' && subject.attributes.video
|
subject?.type === 'post' && subject.attributes.video
|
||||||
? reportDialogMetadata?.current.videoTimestampSeconds
|
? reportDialogMetadata?.current.videoTimestampSeconds
|
||||||
@@ -105,7 +105,7 @@ export function ReportDialog(
|
|||||||
videoTimestampSeconds:
|
videoTimestampSeconds:
|
||||||
seconds !== undefined && seconds >= 1 ? Math.floor(seconds) : undefined,
|
seconds !== undefined && seconds >= 1 ? Math.floor(seconds) : undefined,
|
||||||
}))
|
}))
|
||||||
}, [reportDialogMetadata, subject])
|
}
|
||||||
const propsOnClose = props.onClose
|
const propsOnClose = props.onClose
|
||||||
const onClose = useCallback(() => {
|
const onClose = useCallback(() => {
|
||||||
ax.metric('reportDialog:close', {})
|
ax.metric('reportDialog:close', {})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {useEffect} from 'react'
|
import {useEffect, useEffectEvent} from 'react'
|
||||||
import {Pressable, View} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
import {Image} from 'expo-image'
|
import {Image} from 'expo-image'
|
||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
@@ -19,11 +19,14 @@ export function FollowersPromoBanner({
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
|
|
||||||
useEffect(() => {
|
const onSeen = useEffectEvent(() => {
|
||||||
ax.metric('invite:followersPromo:seen', {})
|
ax.metric('invite:followersPromo:seen', {})
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
// Fire once per mount - parent unmounts the banner when followers > 0 or
|
// Fire once per mount - parent unmounts the banner when followers > 0 or
|
||||||
// when dismissed, so each mount is a distinct impression.
|
// when dismissed, so each mount is a distinct impression.
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
onSeen()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handlePress = () => {
|
const handlePress = () => {
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useState} from 'react'
|
||||||
import type tldts from 'tldts'
|
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() {
|
export function useTLDs() {
|
||||||
const [tlds, setTlds] = useState<typeof tldts>()
|
const [tlds, setTlds] = useState<typeof tldts>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// @ts-expect-error - valid path
|
loadTLDs().then(setTlds)
|
||||||
import('tldts/dist/index.cjs.min.js').then(tlds => {
|
|
||||||
setTlds(tlds)
|
|
||||||
})
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return tlds
|
return tlds
|
||||||
|
|||||||
@@ -29,6 +29,16 @@ const E_SAME_AS_SOURCE_LANGUAGE =
|
|||||||
const E_EMPTY_RESULT = 'Translation result is empty.'
|
const E_EMPTY_RESULT = 'Translation result is empty.'
|
||||||
const E_INVALID_SOURCE_LANGUAGE = 'Invalid source language'
|
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.
|
* 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
|
* 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 => {
|
setRefCounts(prev => {
|
||||||
const newCount = (prev[key] ?? 1) - 1
|
const newCount = (prev[key] ?? 1) - 1
|
||||||
if (newCount <= 0) {
|
if (newCount <= 0) {
|
||||||
const {[key]: _, ...rest} = prev
|
return omitKey(prev, key)
|
||||||
return rest
|
|
||||||
}
|
}
|
||||||
return {...prev, [key]: newCount}
|
return {...prev, [key]: newCount}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ let emojis: Awaited<ReturnType<typeof getEmojis>> | null = null
|
|||||||
|
|
||||||
export function useGetEmojis() {
|
export function useGetEmojis() {
|
||||||
return useCallback(async () => {
|
return useCallback(async () => {
|
||||||
emojis ??= await getEmojis()
|
if (emojis == null) {
|
||||||
|
emojis = await getEmojis()
|
||||||
|
}
|
||||||
return emojis
|
return emojis
|
||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export function StarterPackCard({
|
|||||||
const {gtPhone} = useBreakpoints()
|
const {gtPhone} = useBreakpoints()
|
||||||
const link = useStarterPackLink({view})
|
const link = useStarterPackLink({view})
|
||||||
const record = view.record
|
const record = view.record
|
||||||
|
const isOwnStarterPack = view.creator?.did === currentAccount?.did
|
||||||
|
|
||||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||||
return null
|
return null
|
||||||
@@ -99,7 +100,7 @@ export function StarterPackCard({
|
|||||||
t.atoms.text_contrast_medium,
|
t.atoms.text_contrast_medium,
|
||||||
]}
|
]}
|
||||||
numberOfLines={1}>
|
numberOfLines={1}>
|
||||||
{view.creator?.did === currentAccount?.did
|
{isOwnStarterPack
|
||||||
? _(msg`By you`)
|
? _(msg`By you`)
|
||||||
: _(msg`By ${sanitizeHandle(view.creator.handle, '@')}`)}
|
: _(msg`By ${sanitizeHandle(view.creator.handle, '@')}`)}
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
@@ -46,6 +46,19 @@ function sanitizeDate(date: Date): Date {
|
|||||||
return date
|
return date
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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')
|
||||||
|
}
|
||||||
|
|
||||||
|
function preloadViewShot() {
|
||||||
|
return import('react-native-view-shot')
|
||||||
|
}
|
||||||
|
|
||||||
export function StepInfo({
|
export function StepInfo({
|
||||||
onPressBack,
|
onPressBack,
|
||||||
isServerError,
|
isServerError,
|
||||||
@@ -90,12 +103,11 @@ export function StepInfo({
|
|||||||
|
|
||||||
const tldtsRef = useRef<typeof tldts>(undefined)
|
const tldtsRef = useRef<typeof tldts>(undefined)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// @ts-expect-error - valid path
|
void loadTLDs().then(tldts => {
|
||||||
void import('tldts/dist/index.cjs.min.js').then(tldts => {
|
|
||||||
tldtsRef.current = tldts
|
tldtsRef.current = tldts
|
||||||
})
|
})
|
||||||
// This will get used in the avatar creator a few steps later, so lets preload it now
|
// This will get used in the avatar creator a few steps later, so lets preload it now
|
||||||
void import('react-native-view-shot')
|
void preloadViewShot()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onNextPress = () => {
|
const onNextPress = () => {
|
||||||
|
|||||||
@@ -382,11 +382,10 @@ function Feed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const sourcesChanged = [0, 1, 2].some(
|
||||||
updatedSources[0]?.source !== currentSources[0]?.source ||
|
i => updatedSources[i]?.source !== currentSources[i]?.source,
|
||||||
updatedSources[1]?.source !== currentSources[1]?.source ||
|
)
|
||||||
updatedSources[2]?.source !== currentSources[2]?.source
|
if (sourcesChanged) {
|
||||||
) {
|
|
||||||
setCurrentSources(updatedSources)
|
setCurrentSources(updatedSources)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -659,10 +658,12 @@ function usePlaybackTelemetry({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!active) return
|
if (!active) return
|
||||||
telemetryRef.current ??= createPlaybackTelemetry({
|
if (telemetryRef.current == null) {
|
||||||
surface: 'immersiveFeed',
|
telemetryRef.current = createPlaybackTelemetry({
|
||||||
presentation: 'video',
|
surface: 'immersiveFeed',
|
||||||
})
|
presentation: 'video',
|
||||||
|
})
|
||||||
|
}
|
||||||
const telemetry = telemetryRef.current
|
const telemetry = telemetryRef.current
|
||||||
const preloaded = player.status === 'readyToPlay'
|
const preloaded = player.status === 'readyToPlay'
|
||||||
telemetry.activated({preloaded})
|
telemetry.activated({preloaded})
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ export function useActorAutocompleteFn() {
|
|||||||
const client = useAppviewClient()
|
const client = useAppviewClient()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
async ({query, limit = 8}: {query: string; limit?: number}) => {
|
async ({query: rawQuery, limit = 8}: {query: string; limit?: number}) => {
|
||||||
query = query.toLowerCase()
|
const query = rawQuery.toLowerCase()
|
||||||
let res
|
let res
|
||||||
if (query) {
|
if (query) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -55,14 +55,15 @@ export function useStarterPackQuery({
|
|||||||
return useQuery<app.bsky.graph.defs.StarterPackView>({
|
return useQuery<app.bsky.graph.defs.StarterPackView>({
|
||||||
queryKey: RQKEY(uri ? {uri} : {did, rkey}),
|
queryKey: RQKEY(uri ? {uri} : {did, rkey}),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!uri) {
|
let atUri = uri
|
||||||
uri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
|
if (!atUri) {
|
||||||
} else if (uri && !uri.startsWith('at://')) {
|
atUri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
|
||||||
uri = httpStarterPackUriToAtUri(uri) as string
|
} else if (!atUri.startsWith('at://')) {
|
||||||
|
atUri = httpStarterPackUriToAtUri(atUri) as string
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await client.call(app.bsky.graph.getStarterPack, {
|
const res = await client.call(app.bsky.graph.getStarterPack, {
|
||||||
starterPack: uri as AtUriString,
|
starterPack: atUri as AtUriString,
|
||||||
})
|
})
|
||||||
return res.starterPack
|
return res.starterPack
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -186,12 +186,10 @@ export function TextInput({
|
|||||||
}, [t, fonts])
|
}, [t, fonts])
|
||||||
|
|
||||||
const textDecorated = useMemo(() => {
|
const textDecorated = useMemo(() => {
|
||||||
let i = 0
|
return Array.from(richtext.segments()).map((segment, i) => {
|
||||||
|
|
||||||
return Array.from(richtext.segments()).map(segment => {
|
|
||||||
return (
|
return (
|
||||||
<RNText
|
<RNText
|
||||||
key={i++}
|
key={i}
|
||||||
style={[
|
style={[
|
||||||
inputTextStyle,
|
inputTextStyle,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ export function Pager({
|
|||||||
const dragProgress = useSharedValue(selectedPage)
|
const dragProgress = useSharedValue(selectedPage)
|
||||||
const dragState = useSharedValue<'idle' | 'dragging' | 'settling'>('idle')
|
const dragState = useSharedValue<'idle' | 'dragging' | 'settling'>('idle')
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
|
||||||
setPage: (index: number) => {
|
|
||||||
onTabBarSelect(index)
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
const onTabBarSelect = useCallback(
|
const onTabBarSelect = useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
const scrollY = window.scrollY
|
const scrollY = window.scrollY
|
||||||
@@ -104,6 +98,12 @@ export function Pager({
|
|||||||
[selectedPage, setSelectedPage, onPageSelected, onTabPressed],
|
[selectedPage, setSelectedPage, onPageSelected, onTabPressed],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
setPage: (index: number) => {
|
||||||
|
onTabBarSelect(index)
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View testID={testID} style={s.hContentRegion}>
|
<View testID={testID} style={s.hContentRegion}>
|
||||||
{renderTabBar({
|
{renderTabBar({
|
||||||
|
|||||||
@@ -541,14 +541,12 @@ function useWebListTelemetry({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let taskCount = 0
|
const stats = {taskCount: 0, totalDurationMs: 0, maxDurationMs: 0}
|
||||||
let totalDurationMs = 0
|
|
||||||
let maxDurationMs = 0
|
|
||||||
const observer = new PerformanceObserver(list => {
|
const observer = new PerformanceObserver(list => {
|
||||||
for (const entry of list.getEntries()) {
|
for (const entry of list.getEntries()) {
|
||||||
taskCount++
|
stats.taskCount++
|
||||||
totalDurationMs += entry.duration
|
stats.totalDurationMs += entry.duration
|
||||||
maxDurationMs = Math.max(maxDurationMs, entry.duration)
|
stats.maxDurationMs = Math.max(stats.maxDurationMs, entry.duration)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -560,18 +558,18 @@ function useWebListTelemetry({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const report = () => {
|
const report = () => {
|
||||||
if (taskCount === 0) return
|
if (stats.taskCount === 0) return
|
||||||
ax.metric('web:list:longTasks', {
|
ax.metric('web:list:longTasks', {
|
||||||
itemCount: itemCountRef.current,
|
itemCount: itemCountRef.current,
|
||||||
taskCount,
|
taskCount: stats.taskCount,
|
||||||
totalDurationMs: Math.round(totalDurationMs),
|
totalDurationMs: Math.round(stats.totalDurationMs),
|
||||||
maxDurationMs: Math.round(maxDurationMs),
|
maxDurationMs: Math.round(stats.maxDurationMs),
|
||||||
intervalMs: LONG_TASK_REPORT_INTERVAL,
|
intervalMs: LONG_TASK_REPORT_INTERVAL,
|
||||||
...getWebListDiagnostics(containerRef, rowNodesRef),
|
...getWebListDiagnostics(containerRef, rowNodesRef),
|
||||||
})
|
})
|
||||||
taskCount = 0
|
stats.taskCount = 0
|
||||||
totalDurationMs = 0
|
stats.totalDurationMs = 0
|
||||||
maxDurationMs = 0
|
stats.maxDurationMs = 0
|
||||||
}
|
}
|
||||||
const interval = setInterval(report, LONG_TASK_REPORT_INTERVAL)
|
const interval = setInterval(report, LONG_TASK_REPORT_INTERVAL)
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -567,11 +567,11 @@ let PreviewableUserAvatar = ({
|
|||||||
unstableCacheProfileView(queryClient, profile)
|
unstableCacheProfileView(queryClient, profile)
|
||||||
}, [profile, queryClient, onBeforePress])
|
}, [profile, queryClient, onBeforePress])
|
||||||
|
|
||||||
const onOpenLiveStatus = useCallback(() => {
|
const onOpenLiveStatus = () => {
|
||||||
playHaptic('Light')
|
playHaptic('Light')
|
||||||
ax.metric('live:card:open', {subject: profile.did, from: 'post'})
|
ax.metric('live:card:open', {subject: profile.did, from: 'post'})
|
||||||
liveControl.open()
|
liveControl.open()
|
||||||
}, [liveControl, playHaptic, profile.did])
|
}
|
||||||
|
|
||||||
const avatarEl = (
|
const avatarEl = (
|
||||||
<UserAvatar
|
<UserAvatar
|
||||||
|
|||||||
Reference in New Issue
Block a user