Skip to content

Conversation

Sambit03
Copy link
Contributor

Changes Made

  • Added hydration check using useState and useEffect to prevent rendering before client-side hydration.
  • Updated useSyncExternalStore to safely access localStorage only after hydration.
  • Wrapped JSON.parse in try-catch to prevent runtime errors.
  • Ensured dismissal state persists across reloads and tabs via localStorage and storage event.
Screenshot 2025-07-31 230603

…ation check

- Added hydration guard to avoid flicker during SSR
- Safely parse localStorage value with try-catch
- Applied CSS variable correctly using inline styles
- Ensured announcement hides immediately if previously dismissed
React.useEffect(() => {
setHydrated(true)
}, [])

Copy link
Contributor

Choose a reason for hiding this comment

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

we already have a useIsClient hook for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right I’ve used useIsClient to handle the hydration check and ensure the component doesn’t render fix 08f9df2
And only the hydration check is required to fix this issue

Replaces hydration state logic with the useIsClient hook for client-side checks. Simplifies the component by removing unnecessary state and effect, and streamlines localStorage access.
@mintdart
Copy link
Contributor

mintdart commented Aug 1, 2025

Before your changes: The announcement is displayed by default. If a user has previously dismissed it, the announcement is hidden, causing the table to shift slightly upward.

After your changes: The announcement is hidden by default. However, for new users or when opening in incognito mode, the announcement appears at the top, pushing the table and filters slightly downward.

The issue persists but affects a different group of users.

To fix this, we should use cookies to keep track of whether someone’s dismissed the announcement. Since our frontend’s statically generated, we can inject a script to the <head /> tag before the page loads to check the cookie. Depending on that, we show or hide the announcement banner, so the UI doesn’t shift around for anyone.

@Sambit03
Copy link
Contributor Author

Sambit03 commented Aug 1, 2025

Before your changes: The announcement is displayed by default. If a user has previously dismissed it, the announcement is hidden, causing the table to shift slightly upward.

After your changes: The announcement is hidden by default. However, for new users or when opening in incognito mode, the announcement appears at the top, pushing the table and filters slightly downward.

The issue persists but affects a different group of users.

To fix this, we should use cookies to keep track of whether someone’s dismissed the announcement. Since our frontend’s statically generated, we can inject a script to the <head /> tag before the page loads to check the cookie. Depending on that, we show or hide the announcement banner, so the UI doesn’t shift around for anyone.

That makes sense the layout shift is caused by the delayed rendering of the announcement after hydration. Using cookies and reading them before the page loads ( script in the <head>) would ensure consistent rendering and avoid any UI shift for all users.
I’ll update the implementation to use cookies for tracking the dismissal state and handle the check pre-render, as suggested.

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