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

fix(sdk): safari rendering #2642

Merged
merged 1 commit into from
Jan 28, 2025
Merged
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
17 changes: 15 additions & 2 deletions packages/core/src/sdk/performance/useTTI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { useEffect, useState } from 'react'

const TTI_TIMEOUT = 5000 // 5 seconds without long tasks as a criterion for Time To Interactive - https://web.dev/articles/tti

/**
* Polyfill for requestIdleCallback, which is not available for every browser
* https://caniuse.com/requestidlecallback
*/
function ric(callback: () => void) {
if (window.requestIdleCallback) {
window.requestIdleCallback(callback)
} else {
window.setTimeout(callback, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rapaz, o que exatamenta essa logica de verificar se esta idle faz?
me assustei uma vez com setTimeout de 1 no SF e agora me daparo com isso de novo kkkk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

não precisamos de uma solução mais sofisticada conforme o shim do link?

}
}

export default function useTTI() {
const [isInteractive, setIsInteractive] = useState(false)

Expand All @@ -23,11 +36,11 @@ export default function useTTI() {
observer.disconnect()
setIsInteractive(true) // Sets the state to true when TTI is estimated
} else {
requestIdleCallback(checkTTI) // Keeps checking while the browser is idle
ric(checkTTI) // Keeps checking while the browser is idle
}
}

requestIdleCallback(checkTTI)
ric(checkTTI)
}
}, [])

Expand Down
Loading