Skip to content

Commit 57861cd

Browse files
committedFeb 20, 2025
perf(useScript): avoid registering callbacks when ssr
1 parent b1dd378 commit 57861cd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed
 

Diff for: ‎packages/unhead/src/scripts/useScript.ts

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
5555
const _cbs: ScriptInstance<T>['_cbs'] = { loaded: [], error: [] }
5656
const _uniqueCbs: Set<string> = new Set<string>()
5757
const _registerCb = (key: 'loaded' | 'error', cb: any, options?: EventHandlerOptions) => {
58+
// events will never run
59+
if (head.ssr) {
60+
return
61+
}
5862
if (options?.key) {
5963
const key = `${options?.key}:${options.key}`
6064
if (_uniqueCbs.has(key)) {

0 commit comments

Comments
 (0)
Please sign in to comment.