-
Notifications
You must be signed in to change notification settings - Fork 391
fix(metadata): stricter detection of user agent #3184
Conversation
1. react native has window, but no navigator 2. in potentially other environments document might be undefined
42771bf
to
b9c99a1
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit dc31cd0:
|
✔️ Deploy Preview for react-instantsearch ready! 🔨 Explore the source changes: 42771bf 🔍 Inspect the deploy log: https://app.netlify.com/sites/react-instantsearch/deploys/61795bad2eb41d0007172a44 😎 Browse the preview: https://deploy-preview-3184--react-instantsearch.netlify.app |
Thanks for checking @ClaudionorJunior, @johnsoncwb, @LFMAKER, did you confirm this works in your application? |
@Haroenv Yes, tested and approved. |
@Haroenv This works here, no more crashs. |
✔️ Deploy Preview for react-instantsearch ready! 🔨 Explore the source changes: dc31cd0 🔍 Inspect the deploy log: https://app.netlify.com/sites/react-instantsearch/deploys/61795e462d1b6000086d110d 😎 Browse the preview: https://deploy-preview-3184--react-instantsearch.netlify.app |
@@ -48,6 +48,17 @@ describe('isMetadataEnabled', () => { | |||
expect(isMetadataEnabled()).toBe(false); | |||
}); | |||
|
|||
it("does not enable when there's no navigator (react native)", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("does not enable when there's no navigator (react native)", () => { | |
it("does not enable when there's no navigator (React Native)", () => { |
typeof window === 'object' && | ||
typeof window.navigator === 'object' && | ||
typeof window.navigator.userAgent === 'string' && | ||
window.navigator.userAgent.includes('Algolia Crawler') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code works so feel free to merge as is, but this should work no?
typeof window === 'object' && | |
typeof window.navigator === 'object' && | |
typeof window.navigator.userAgent === 'string' && | |
window.navigator.userAgent.includes('Algolia Crawler') && | |
window?.navigator?.userAgent?.includes('Algolia Crawler') && |
@Haroenv thank you so much! have a nice day. |
This has been released in 6.15.0, thanks for your help all! |
Summary
see #3145
Result
more robust check of environments.
As these are hard to test, I didn't include a test here per se