Skip to content
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

Simplify KaizenProvider #5426

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

vietanhtran16
Copy link
Contributor

@vietanhtran16 vietanhtran16 commented Dec 23, 2024

Important: Request PR reviews on Slack

Please reach out to the design system team on Slack in #prod_design_system for PR reviews. GitHub notifications (e.g. from tagging a person) are not actively monitored.

Why

We have built a shared component as part of @cultureamp/conversations-shared-ui which makes use of useToastNotification. This hook relies on KaizenProvider being set up by the consumer and most importantly, the consumer needs to have the exact same version as the required peer dependency that we specify in @cultureamp/conversations-shared-ui. That is not always gonna be the case though and it will be fragile hoping for consumers to always have the same version.

Due to that, I am setting up KaizenProvider in our component alongside with other providers to ensure that we dont have to rely on the consumers and prevent it breaking in production (it will throw error when the context is not found)
image

When I do the above though, it threw this error which Michael encoutered as well so decided to take a look at KaizenProvider and noticed that it could be improved so thought to try to see if it fixes the issue above and it did.

What

@vietanhtran16 vietanhtran16 requested a review from a team as a code owner December 23, 2024 01:32
Copy link

changeset-bot bot commented Dec 23, 2024

🦋 Changeset detected

Latest commit: 032f7d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kaizen/components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 23, 2024

✨ Here is your branch preview! ✨

Last updated for commit 032f7d8: Fix order import

setDocumentIsAvailable(true)
}
}, [documentIsAvailable])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't need to be a dependency, nothing inside useEffect is referring to it

@@ -175,26 +175,27 @@ export const NoDuplicatesWithSameId: Story = {
render: () => {
const { addToastNotification } = useToastNotification()

useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this story was failing before I made this change due to the toast was not visible.

Not sure why that was the case but I think using useEffect here might have cause some issue as I suspect addToastNotification is not being wrapped inside a useCallBack so having it inside useEffect dependency will cause it to be called many times

}, [addToastNotification])

return <div>Irrelevant content</div>
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue I'd have with you changing this test is that I think some teams actually use addToastNotification in a useEffect in a similar fashion to this. If it fails here, then it will start throwing errors for consumers too.

I suggest you make a canary and test against performance-review-cycles-ui and see if everything passes or not.
Slack thread of the SSR issue when ToastNotificationProvider was introduced: https://cultureamp.slack.com/archives/C0189KBPM4Y/p1700782380804669

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me test it out. I reckon all these addToastNotification updateToastNotification removeToastNotification clearToastNotifications functions should be wrapped inside an useCallback tbh as they can be used as dependency in useEffect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I will need to test a canary from 1.67.0 version instead as the latest version has some issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read through your comment here about what the [] dependency array which will cause the issue that I am seeing with this story hence trying to fix it.

That is weird though as documentIsAvailable is not even being used inside useEffect - having it in the dependency array will just cause the useEffect to run again after setDocumentIsAvailable(true) has been called

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always get this error with pnpm storybook even after pnpm reset so unable to run locally and test it
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants