Skip to content

Commit

Permalink
Added Safari specific handling in triggerAsyncCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
salmenus committed Aug 5, 2024
1 parent d3ee03a commit 1f7f789
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {CallbackFunction} from '../../../types/callbackFunction';

export const triggerAsyncCallback = (trigger: CallbackFunction, delay: number = 10) => {
const isHighPerfJsEngine = navigator?.userAgent?.includes('Safari');

This comment has been minimized.

Copy link
@dchenk

dchenk Aug 15, 2024

Contributor

This causes an error in Next.js server-side: ReferenceError: navigator is not defined

@salmenus

This comment has been minimized.

Copy link
@salmenus

salmenus Aug 15, 2024

Author Member

The page importing @nlux should be rendered as a client-side page using 'use client' directive.
Have you tried that ?

This comment has been minimized.

Copy link
@salmenus

salmenus Aug 15, 2024

Author Member

Merging your PR

This comment has been minimized.

Copy link
@salmenus

salmenus Aug 15, 2024

Author Member

Fix published in 2.17.1


// TODO: To be replaced with a pure React implementation for submitPrompt that relies on React rendering cycle
const defaultAsyncDelay: 1 | 10 = isHighPerfJsEngine ? 10 : 1; // Efficient async scheduling for Safari

export const triggerAsyncCallback = (trigger: CallbackFunction, delay: number = defaultAsyncDelay) => {
setTimeout(() => {
trigger();
}, delay);
Expand Down

0 comments on commit 1f7f789

Please sign in to comment.