Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components/perf/dynamicRendering): Decouple crawlers checking fr… #668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions components/perf/dynamicRendering/src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import PropTypes from 'prop-types'

import {checkLegitimateCrawler} from '@s-ui/js/lib/ua-parser'

import LazyContent from './lazyContent.js'

import './index.scss'

const BOTS_USER_AGENTS = [
'googlebot',
'google-structured-data-testing-tool',
'bingbot',
'linkedinbot',
'mediapartners-google',
'debugbear'
]

function checkUserAgentIsBot(userAgent, botsUserAgents) {
const lowerCaseUserAgent = userAgent.toLowerCase()
// check if the userAgent is a bot
return botsUserAgents.some(ua => lowerCaseUserAgent.includes(ua))
}

export default function PerfDynamicRendering({
botsUserAgents = BOTS_USER_AGENTS,
botsUserAgents,
children,
disabled,
forceRender,
Expand All @@ -29,7 +16,7 @@ export default function PerfDynamicRendering({
rootMargin,
userAgent
}) {
const isBot = checkUserAgentIsBot(userAgent, botsUserAgents)
const isBot = checkLegitimateCrawler(userAgent, botsUserAgents)

// Force render in server and client
if (forceRender) return children
Expand Down
Loading