-
Notifications
You must be signed in to change notification settings - Fork 1
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
HCRC-109 | fix(askem): fix Askem looping to fetch rns.js on article pages #529
Conversation
Events-Helsinki branch is deployed to platta: https://tapahtumat-pr529.dev.hel.ninja 🚀🚀🚀 |
Hobbies-Helsinki branch is deployed to platta: https://harrastukset-pr529.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://tapahtumat-pr529.dev.hel.ninja 😆🎉🎉🎉 |
TestCafe result is success for https://harrastukset-pr529.dev.hel.ninja 😆🎉🎉🎉 |
Sports-Helsinki branch is deployed to platta: https://liikunta-pr529.dev.hel.ninja 🚀🚀🚀 |
VENUE GRAPHQL PROXY is deployed to platta: https://venue-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
EVENTS GRAPHQL PROXY is deployed to platta: https://events-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://liikunta-pr529.dev.hel.ninja 😆🎉🎉🎉 |
const newAskemConfiguration: AskemConfigs = { | ||
...askemConfigurationInput, | ||
consentGiven: askemConsentGiven, | ||
}; | ||
|
||
if (!askemInstance || !isEqual(askemConfiguration, newAskemConfiguration)) { | ||
setAskemConfiguration(newAskemConfiguration); | ||
setAskemInstance(createAskemInstance(newAskemConfiguration)); | ||
} |
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 don't get this. Handling this wit a state should not make a difference compared to a memo. The memo is just a lot cleaner. Both are executed when the dependency array changes.
I need to test this. How was the issue reproducable?
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.
Found the instructions from the PR description 😝
Testing
checkout PR's branch locally because review environments don't have Askem enabled
cd apps/sports-helsinki
yarn
yarn dev
open page https://localhost:3000/fi/articles/yleinen/testiartikkeli-syyskuu in browser
make sure Askem cookies are allowed, if you're not sure clear localhost:3000's cookies or at least the city-of-helsinki-cookie-consents cookie
do twice in a row:
scroll down to the bottom of the page
scroll back up to the top of the page
reload
What is expected:
Everything should be fine and the network shouldn't be loading anything in a seemingly infinite loop.
Askem functionality should also work all around correctly.
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.
useMemo with any object variables is relatively useless IMO as it doesn't compare the objects' contents but simply the references themselves → useMemo always changes the return value if any of useMemo's dependency list's objects' references change even though their contents stay the same. I added deep equality checking to get around this.
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 actually can compare deeply: the dependency array could be something like [JSON.stringify(object)]
. As a reference I found this for example: https://javascript.plainenglish.io/a-less-known-trick-with-react-hook-dependencies-8dafaca7a150
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.
According to useMemo documentation it seems they're suggesting to memoize objects used as useMemo dependencies → recursively going back to only using primitive types as dependencies in useMemo in the leaf nodes of the useMemo calls.
The JSON.stringify has some limitations:
- BigInt -> throw
- undefined -> null
- Function -> nothing or null
- Symbol -> nothing or null
- NaN -> null
- Infinity -> null
- Map -> "{}"
- Set -> "{}"
which could possibly be overcome with the use of the replacer parameter.
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.
Okay, I'm 99% sure, that the problem is in the LayoutCards-module (that is also in the example page of this PR) When I exclude all the
|
There are 2 commits that I call improvements in #532 ! 😌 I think that the changes in this PR could be taken in action, but it just does not fix what it is saying to fix. |
Hobbies-Helsinki branch is deployed to platta: https://harrastukset-pr529.dev.hel.ninja 🚀🚀🚀 |
Events-Helsinki branch is deployed to platta: https://tapahtumat-pr529.dev.hel.ninja 🚀🚀🚀 |
NOTE: - There seems to be an underlying issue here that is not fully fixed by this commit. This commit fixes the infinite looping to fetch Askem's rns.js script and the unnecessary updating of AskemInstance but it's a tip of the iceberg so to speak, there's still something being rerendered underneath. So, more work is needed to fix the underlying issue. parts: - don't render AskemProvider and AskemFeedbackContainer on server-side - don't update used AskemInstance except when it really changes, use deep equality to compare also: - add more fields and documentation to Askem's data using https://docs.reactandshare.com/ - pass all the Askem fields to window.rnsData - fix AskemContext and AskemProvider default import renaming typos refs HCRC-106
TestCafe result is success for https://harrastukset-pr529.dev.hel.ninja 😆🎉🎉🎉 |
TestCafe result is success for https://tapahtumat-pr529.dev.hel.ninja 😆🎉🎉🎉 |
Sports-Helsinki branch is deployed to platta: https://liikunta-pr529.dev.hel.ninja 🚀🚀🚀 |
VENUE GRAPHQL PROXY is deployed to platta: https://venue-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://liikunta-pr529.dev.hel.ninja 😆🎉🎉🎉 |
1d47466
to
721cb86
Compare
EVENTS GRAPHQL PROXY is deployed to platta: https://events-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Events-Helsinki branch is deployed to platta: https://tapahtumat-pr529.dev.hel.ninja 🚀🚀🚀 |
Hobbies-Helsinki branch is deployed to platta: https://harrastukset-pr529.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://tapahtumat-pr529.dev.hel.ninja 😆🎉🎉🎉 |
TestCafe result is success for https://harrastukset-pr529.dev.hel.ninja 😆🎉🎉🎉 |
Sports-Helsinki branch is deployed to platta: https://liikunta-pr529.dev.hel.ninja 🚀🚀🚀 |
VENUE GRAPHQL PROXY is deployed to platta: https://venue-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
EVENTS GRAPHQL PROXY is deployed to platta: https://events-graphql-proxy-pr529.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://liikunta-pr529.dev.hel.ninja 😆🎉🎉🎉 |
The commits from #532 are merged into this PR. Changed the PR's name and the first commit's commit title to reflect what is being done:
Also added a note to the first commit's commit message:
|
Description
fix(askem): fix Askem looping to fetch rns.js on article pages
NOTE:
by this commit. This commit fixes the infinite looping to fetch
Askem's rns.js script and the unnecessary updating of AskemInstance
but it's a tip of the iceberg so to speak, there's still something
being rerendered underneath. So, more work is needed to fix the
underlying issue.
parts:
deep equality to compare
also:
https://docs.reactandshare.com/
refs HCRC-106
refactor: improve Askem api key api config
refactor: move Matomo, Askem and HDS-style handling of the BaseApp to new files
HCRC-106
Issues
Closes
HCRC-109
Related
Testing
city-of-helsinki-cookie-consents
cookieWhat is expected:
Automated tests
Manual testing
Tested locally and couldn't get the infinite network loop fetching Askem's rns.js script to happen anymore.
Screenshots
Additional notes