feat: prevent search engines from indexing Discover feed content as page descriptions

This commit is contained in:
Caidan Williams
2025-08-22 18:25:35 -07:00
parent 0517768cd3
commit 6ddc268b91
2 changed files with 72 additions and 38 deletions
+43 -38
View File
@@ -29,6 +29,7 @@ import {FAB} from '../util/fab/FAB'
import {type ListMethods} from '../util/List'
import {LoadLatestBtn} from '../util/load-latest/LoadLatestBtn'
import {MainScrollProvider} from '../util/MainScrollProvider'
import {NoSnippetWrapper} from '../util/NoSnippetWrapper'
const POLL_FREQ = 60e3 // 60sec
@@ -132,45 +133,49 @@ export function FeedPage({
const shouldPrefetch = isNative && isPageAdjacent
return (
<View testID={testID} {...(isDiscoverFeed && {'data-nosnippet': true})}>
<MainScrollProvider>
<FeedFeedbackProvider value={feedFeedback}>
<PostFeed
testID={testID ? `${testID}-feed` : undefined}
enabled={isPageFocused || shouldPrefetch}
feed={feed}
feedParams={feedParams}
pollInterval={POLL_FREQ}
disablePoll={hasNew || !isPageFocused}
scrollElRef={scrollElRef}
onScrolledDownChange={setIsScrolledDown}
onHasNew={setHasNew}
renderEmptyState={renderEmptyState}
renderEndOfFeed={renderEndOfFeed}
headerOffset={headerOffset}
savedFeedConfig={savedFeedConfig}
isVideoFeed={isVideoFeed}
<NoSnippetWrapper enabled={isDiscoverFeed}>
<View testID={testID}>
<MainScrollProvider>
<FeedFeedbackProvider value={feedFeedback}>
<PostFeed
testID={testID ? `${testID}-feed` : undefined}
enabled={isPageFocused || shouldPrefetch}
feed={feed}
feedParams={feedParams}
pollInterval={POLL_FREQ}
disablePoll={hasNew || !isPageFocused}
scrollElRef={scrollElRef}
onScrolledDownChange={setIsScrolledDown}
onHasNew={setHasNew}
renderEmptyState={renderEmptyState}
renderEndOfFeed={renderEndOfFeed}
headerOffset={headerOffset}
savedFeedConfig={savedFeedConfig}
isVideoFeed={isVideoFeed}
/>
</FeedFeedbackProvider>
</MainScrollProvider>
{(isScrolledDown || hasNew) && (
<LoadLatestBtn
onPress={onPressLoadLatest}
label={_(msg`Load new posts`)}
showIndicator={hasNew}
/>
</FeedFeedbackProvider>
</MainScrollProvider>
{(isScrolledDown || hasNew) && (
<LoadLatestBtn
onPress={onPressLoadLatest}
label={_(msg`Load new posts`)}
showIndicator={hasNew}
/>
)}
)}
{hasSession && (
<FAB
testID="composeFAB"
onPress={onPressCompose}
icon={<ComposeIcon2 strokeWidth={1.5} size={29} style={s.white} />}
accessibilityRole="button"
accessibilityLabel={_(msg({message: `New post`, context: 'action'}))}
accessibilityHint=""
/>
)}
</View>
{hasSession && (
<FAB
testID="composeFAB"
onPress={onPressCompose}
icon={<ComposeIcon2 strokeWidth={1.5} size={29} style={s.white} />}
accessibilityRole="button"
accessibilityLabel={_(
msg({message: `New post`, context: 'action'}),
)}
accessibilityHint=""
/>
)}
</View>
</NoSnippetWrapper>
)
}
+29
View File
@@ -0,0 +1,29 @@
import {type ViewProps} from 'react-native'
// @ts-expect-error untyped
import {unstable_createElement} from 'react-native-web'
import {isWeb} from '#/platform/detection'
interface Props extends ViewProps {
enabled: boolean
}
/**
* NoSnippetWrapper prevents search engines from displaying snippets of its content.
*
* If running on web and enabled, wraps children in a <div> with data-nosnippet attribute.
* Otherwise, renders children directly.
*
* @param enabled - Whether to apply the data-nosnippet attribute.
* @param viewProps - Additional props for the wrapper element.
*/
export function NoSnippetWrapper({enabled, ...viewProps}: Props) {
if (isWeb && enabled) {
return unstable_createElement('div', {
...viewProps,
'data-nosnippet': '',
})
}
return <>{viewProps.children}</>
}