You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loving Aptabase so far, but running into an annoyance with using this SDK with SSR frameworks (specifically SvelteKit). I want to exclusively run events clientside, so I make sure to run init and trackEvent only on the client. However, functions like getBrowserLocale are called on import to create defaultLocale (https://github.com/aptabase/aptabase-js/blob/main/packages/shared.ts#L1), which causes an error since navigator.languages does not exist (TypeError: Cannot read properties of undefined (reading 'length'))
Would you accept a PR to either:
Make sure navigator.languages exists before checking length
or
defaultLocale is a "singleton" that is first created when it is requested (which seems to only be in sendEvent()
I'd be happy to do the work, just want to chat about how it should be done (if at all)
The text was updated successfully, but these errors were encountered:
This definitely needs a fix, and it probably makes more sense to read the locale value as late as possible - so like you mentioned in option 2, on sendEvent.
That way when sendEvent is called and is executed on client side navigator.languages should be available.
Adding an extra check with navigator.languages?.length also helps, but it doesn't result in the correct language being loaded, so would go with reading it on sendEvent primarily
`shared.ts` currently reads the default browser locale and is debug on import, which causes
issueswhen imported in a server component. This moves the reads for those to whenever the first
event issent and those values are actually required, which is typically on the client.
fixaptabase#7
Loving Aptabase so far, but running into an annoyance with using this SDK with SSR frameworks (specifically SvelteKit). I want to exclusively run events clientside, so I make sure to run
init
andtrackEvent
only on the client. However, functions likegetBrowserLocale
are called on import to createdefaultLocale
(https://github.com/aptabase/aptabase-js/blob/main/packages/shared.ts#L1), which causes an error sincenavigator.languages
does not exist (TypeError: Cannot read properties of undefined (reading 'length')
)Would you accept a PR to either:
navigator.languages
exists before checking lengthor
defaultLocale
is a "singleton" that is first created when it is requested (which seems to only be insendEvent()
I'd be happy to do the work, just want to chat about how it should be done (if at all)
The text was updated successfully, but these errors were encountered: