-
Notifications
You must be signed in to change notification settings - Fork 213
fix: session replay on react native web #2592
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
2 files reviewed, no comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
|
Size Change: +2.26 kB (+0.04%) Total Size: 5.05 MB
ℹ️ View Unchanged
|
| }, | ||
| }, | ||
|
|
||
| // persistence: 'memory', |
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.
leftover comment here?
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.
no, just a handy comment to avoid reinstalling plugins https://posthog.com/docs/libraries/react-native#react-native-web-and-macos
| if (typeof File === 'undefined') { | ||
| ;(global as any).File = function () {} | ||
| } |
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.
I wonder what functionality we may be dropping with this empty stub here? I assume rrweb uses this somehow
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.
its us
| use_val = encodeURIComponent(isFile(val) ? val.name : val.toString()) |
we do instanceof isFile, so this returns false on react native.
The feature impact:
- Session Recording Network Capture - PostHog won't be able to
properly serialize FormData containing File objects when recording
network requests- General HTTP requests - Any PostHog requests that include
FormData with files won't serialize correctlyWhat will happen without the polyfill:
- If FormData contains a File object, the isFile() check crashes
instead of returning false- The file would be converted to [object File] instead of the
filename- Session recording network capture may miss or incorrectly record
file upload requestsWith the File polyfill:
- isFile() returns false for all objects (since nothing is
actually a File in React Native)- Files get converted via .toString() instead of .name
- Session recording and requests work, but file names aren't
captured (graceful degradation)So the File polyfill ensures session recording and network
requests don't crash in React Native web, with minimal
functionality loss.
thats my friend "Claudio" :D
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.
Looks like a simple fix, but I think @PostHog/team-replay will have the final say here since, web :)
Example looks good!
pauldambra
left a comment
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.
feels like the important thing here would be the docs on how to use this - but 🙌
agree, a good start would be to point out to the JS SDK tbh since its the very same thing. |
Problem
workaround for #2157
otherwise users would have to polyfill manually.
ideally users init the SDK conditionally, if mobile: uses the RN SDK, if web: uses the JS SDK
example: https://us.posthog.com/shared/6K26C6g8ljMoa0ZDOR9nJkXHchLHJg?t=4
Changes
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file