-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix vica hydration bug #1018
Fix vica hydration bug #1018
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 257 Passed, 36 Skipped, 44.9s Total Time |
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.
lgtm! jsut to double check why this bug occurs and how this fixes:
- previously, we rendered both
VicaStylesheet
+VicaWidget
on the server - when we sent it to the client side,
chat.js
altered some portions of the html? (hence causing the bug) - how, we mark
Widget
asuse client
so that on the server, it doesn't do anything - on client side now, it's initially
null
(so matches server) - fetches
VicaWidget
sincewindow
is defined (technically this is the rsc script which then re-renders) VicaWidget
loads in properly
if this isnt true, please dismiss the review!
|
||
export const VicaWidget = ({ | ||
ScriptComponent = "script", | ||
...props | ||
}: VicaProps) => { | ||
// to not render during static site generation on the server | ||
if (typeof window === "undefined") return null |
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.
nit: prefer !window
im not exactly very sure why this is happening because the integration doc for VICA seems to differ for each agency 😢 my observation is that on staging site, VICA widgets actually rendered before disappearing. my suspicion is that during SSG, VicaWidget was indeed rendered during SSG and modifed the DOM after the initial render, leading to differences between the server-rendered HTML and the client-side DOM during hydration. |
Problem
VICA widget sometimes loading sometimes not
Error log shows https://react.dev/errors/418?args%5B%5D=
Suspected it's due to it being rendered SSG and causing incocrrect hydration error
Solution
Breaking Changes
Bug Fixes:
tested on STG site and works
use client
Tests