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
Add loader if center value hasn't rendered #4512
base: main
Are you sure you want to change the base?
Conversation
I got nerd-sniped into trying to find out why the colours wouldn't show up, and found out that it's because our Content Security Policy doesn't allow defining styles via the I'm not sure I'm able to reproduce what the issue is with the center value, but possibly that PR also solves that? |
Preview URL 🚀 : https://blurts-server-pr-4512-mgjlpikfea-uk.a.run.app |
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.
Thanks for picking this up, I think the addition of a loader makes sense. I did spend a bit of effort trying to understand what went wrong, which I've detailed inline - I think there's a small change we can make that then enables not suppressing the test error, but outright avoiding it.
And if you don't mind, could you add a story for the loader? Curious to see what the two different versions look like, which is a bit of a hassle to test now :)
(Oh, and apologies for the delayed review, I got a bit buried in messages.)
// Ignoring this, otherwise tests will complain: | ||
// > Warning: A suspended resource finished loading inside a test, but the | ||
// > event was not wrapped in act(...). | ||
// > When testing, code that resolves suspended data should be wrapped into | ||
// > act(...) | ||
/* c8 ignore start */ |
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.
OK, so I think I figured out why the center value isn't available on page load: it is rendered by a getFragment
, which replaces <tags>
in a string with actual HTML tags. However, to do this safely (i.e. to avoid code injection from variables), it uses browser APIs to instantiate DOM elements for those actual tags - and those APIs aren't available during pre-rendering. This is why getFragment
only renders on the client-side.
So the loading animation while we await the client-side render sounds like a good idea. However, it should be sufficient to use the useHasRenderedClientSide
hook to determine whether to show it, rather than have the effect dependent on props.data
, nrText
and labelText
. Also, we can add a comment describing the above to explain why we have it :)
And then with #4551, you should be able to avoid the test from erroring by adding a jest.mock
call for the useHasRenderedClientSide
hook.
Preview URL 🚀 : https://blurts-server-pr-4512-mgjlpikfea-uk.a.run.app |
References:
Jira: MNTOR-3154
Description
Screenshot (if applicable)
Screen.Recording.2024-05-14.at.4.57.18.PM.mov
How to test
Checklist (Definition of Done)