-
Notifications
You must be signed in to change notification settings - Fork 230
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
Move chartbeat out of unmount and refactor to avoid unwanted reloading #3621
Comments
Allthough the PoC above was merged the next steps for this issue are to determine if there is a more optimal solution and refactor as required. |
Needs investigation to see if the current chartbeat implementation is up to scratch. Worth checking test coverage too. A senior could pair with someone on this |
Myself and Andrew have been pairing on this issue and we would like some context around why it is necessary to use the |
@jroebu14 IIFE with the async chartbeat script tag just initialises chartbeat. If this wasn't an SPA we could do without |
Is your feature request related to a problem? Please describe.
Our current chartbeat code is run inside the article main. This means it gets unmounted when you navigate to a new article (due to the loading screen).
Currently the unmounting logic causes issues as it reinitialises charbeat by reloading the script again.
It also doesnt call
window.pSUPERFLY.virtualPage
in the right place, calling it on unmount instead of when a new article is loaded.Describe the solution you'd like
Move the chartbeat logic into pageWrapper or contexts, (or anouther new layer above
withLoading
to avoid being unmounted.Possible sollution:
Move it into
UserContext
(or anouther context), creating auseChartbeat
function which takesconfig
as an argument. WhenuseChartbeat
is first called it renders the scripts using helmet (and never unmounts them).If the
config
argument changes (data changes), theuseChartbeat
function will callwindow.pSUPERFLY.virtualPage
for you.We need to be very careful to use the
useEffect
hook properly. Theconfig
object should only change whendata
changes, not on renders. If this is done wrong, even ifconfig
is regenerated the same across the renders,useEffect
will see it as a new object, callingwindow.pSUPERFLY.virtualPage
too many timesTesting notes
This issue will require a complete testing of chartbeat functionality on articles pages when this refactor is done.
Dev insight: Will Cypress tests be required or are unit tests sufficient? Will there be any potential regression? etc
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: