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

fix: theme hydration issues in various browsers #153

Merged
merged 2 commits into from
Dec 13, 2024
Merged

Conversation

chalabi2
Copy link
Collaborator

@chalabi2 chalabi2 commented Dec 12, 2024

fixes #129

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced wallet connection management with improved user feedback during connection processes.
    • Added tooltips for "Endpoints" and "Contacts" buttons in the SideNav for better user interaction.
    • Introduced new wallet options, including "Email" and "SMS" authentication methods.
  • Improvements

    • Streamlined theme management logic for more responsive user preferences.
    • Enhanced Tailwind CSS configuration with new themes and animations.
  • Bug Fixes

    • Resolved issues related to theme initialization and persistence in local storage.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request involve significant updates across various components, primarily focusing on theme management and wallet connection states. The SideNav component's state management has been simplified by removing the isdark state variable, while tooltips have been added for improved user interaction. The WalletSection and IconWallet components have been enhanced to manage wallet connection statuses more effectively. Additionally, the ThemeProvider has been updated to improve theme initialization and management, and the Tailwind CSS configuration has been modified to refine theme and animation settings.

Changes

File Change Summary
components/react/sideNav.tsx Removed isdark state, simplified theme toggle logic, added tooltips for buttons, adjusted button styles.
components/wallet.tsx Introduced localStatus for wallet connection management, added timeout handling for connection status.
contexts/theme.tsx Added getInitialTheme function, improved theme initialization and management logic.
pages/_app.tsx Integrated new wallet options, added logging for theme changes, refined drawer visibility management.
tailwind.config.js Updated daisyui configuration, added new screen sizes and animations.

Assessment against linked issues

Objective Addressed Explanation
Ensure theme functionality is consistent across browsers (#129)

Possibly related PRs

Suggested labels

enhancement, render

Suggested reviewers

  • fmorency

Poem

In the land of code where rabbits play,
Themes now toggle in a seamless way.
Tooltips dance with a gentle grace,
While wallets connect in a cozy space.
Hooray for changes, let’s hop and cheer,
For a smoother app, we hold so dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 9.67742% with 28 lines in your changes missing coverage. Please review.

Project coverage is 58.13%. Comparing base (88e8e7b) to head (7b3edbb).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
contexts/theme.tsx 10.00% 27 Missing ⚠️
components/wallet.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
+ Coverage   57.01%   58.13%   +1.12%     
==========================================
  Files         145      147       +2     
  Lines       14436    14842     +406     
==========================================
+ Hits         8230     8628     +398     
- Misses       6206     6214       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
contexts/theme.tsx (1)

47-49: Simplified theme toggle implementation

The theme toggle is now implemented using a functional state update, making it more reliable and easier to maintain.

Consider adding a comment explaining the theme toggle behavior:

 const toggleTheme = () => {
+  // Toggle between light and dark theme using functional state update
   setTheme(current => (current === 'light' ? 'dark' : 'light'));
 };
pages/_app.tsx (1)

51-58: Theme debugging enhancement

The added logging helps debug theme-related issues across browsers. However, consider using a development flag for these logs.

Consider wrapping the logs with a development check:

 useEffect(() => {
   if (typeof window !== 'undefined') {
-    console.log({ localStorageTheme: localStorage?.getItem('theme') });
+    if (process.env.NODE_ENV === 'development') {
+      console.log({ localStorageTheme: localStorage?.getItem('theme') });
+      console.log({ theme });
+    }
   }
-  console.log({ theme });
 }, [theme]);
components/wallet.tsx (2)

Line range hint 38-52: LGTM! Robust connection status handling.

The implementation of localStatus with a 10-second timeout effectively prevents infinite "connecting" states, with proper cleanup to prevent memory leaks.

Consider adding an error message or notification when the connection times out to improve user feedback:

 if (status === WalletStatus.Connecting) {
   timeoutId = setTimeout(() => {
     setLocalStatus(WalletStatus.Error);
+    // Optional: Show error notification
+    console.warn('Wallet connection timed out after 10 seconds');
   }, 10000);
 }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 38-38: components/wallet.tsx#L38
Added line #L38 was not covered by tests


Line range hint 171-251: Consider improving accessibility and code reusability.

While the implementation is solid, there are opportunities for improvement:

  1. Extract the connection status handling logic into a custom hook to avoid duplication:
function useWalletConnection(chainName: string) {
  const { status, connect, openView } = useChain(chainName);
  const [localStatus, setLocalStatus] = useState(status);
  // ... timeout logic ...
  return { localStatus, connect, openView };
}
  1. Add ARIA labels for better accessibility:
 <button
   className="p-2 hover:text-primary rounded-t-md w-full flex justify-center items-center"
   id="copyButton"
+  aria-label="Copy wallet address"
   onClick={() => {
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 38-38: components/wallet.tsx#L38
Added line #L38 was not covered by tests

components/react/sideNav.tsx (1)

85-88: Enhanced UX with accessible tooltips.

The addition of tooltips improves user experience by providing clear context for navigation items.

Consider adding aria-label attributes for better accessibility:

 <span className="tooltip fixed z-[9999] left-[6.8rem] px-3 py-2 bg-primary text-white text-sm font-medium rounded-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 ease-in-out whitespace-nowrap"
+      role="tooltip"
+      aria-label="Navigation tooltip">

Also applies to: 95-97

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88e8e7b and e63fab6.

📒 Files selected for processing (5)
  • components/react/sideNav.tsx (6 hunks)
  • components/wallet.tsx (1 hunks)
  • contexts/theme.tsx (2 hunks)
  • pages/_app.tsx (4 hunks)
  • tailwind.config.js (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/wallet.tsx

[warning] 38-38: components/wallet.tsx#L38
Added line #L38 was not covered by tests

contexts/theme.tsx

[warning] 13-16: contexts/theme.tsx#L13-L16
Added lines #L13 - L16 were not covered by tests


[warning] 21-22: contexts/theme.tsx#L21-L22
Added lines #L21 - L22 were not covered by tests


[warning] 24-24: contexts/theme.tsx#L24
Added line #L24 was not covered by tests


[warning] 26-28: contexts/theme.tsx#L26-L28
Added lines #L26 - L28 were not covered by tests


[warning] 30-31: contexts/theme.tsx#L30-L31
Added lines #L30 - L31 were not covered by tests


[warning] 33-33: contexts/theme.tsx#L33
Added line #L33 was not covered by tests


[warning] 36-36: contexts/theme.tsx#L36
Added line #L36 was not covered by tests


[warning] 38-50: contexts/theme.tsx#L38-L50
Added lines #L38 - L50 were not covered by tests

🔇 Additional comments (8)
contexts/theme.tsx (3)

13-18: Improved server-side rendering compatibility

The new getInitialTheme function ensures consistent initial theme rendering by defaulting to 'light' during SSR, preventing hydration mismatches.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 13-16: contexts/theme.tsx#L13-L16
Added lines #L13 - L16 were not covered by tests


21-33: Enhanced client-side theme initialization

The initialization logic now properly handles:

  1. Local storage theme preference
  2. System color scheme preference
  3. State initialization tracking

This change fixes the theme hydration issues by ensuring proper theme initialization on the client side.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 21-22: contexts/theme.tsx#L21-L22
Added lines #L21 - L22 were not covered by tests


[warning] 24-24: contexts/theme.tsx#L24
Added line #L24 was not covered by tests


[warning] 26-28: contexts/theme.tsx#L26-L28
Added lines #L26 - L28 were not covered by tests


[warning] 30-31: contexts/theme.tsx#L30-L31
Added lines #L30 - L31 were not covered by tests


[warning] 33-33: contexts/theme.tsx#L33
Added line #L33 was not covered by tests


36-45: Robust theme application with initialization check

The theme application is now guarded by isInitialized check, preventing unwanted theme flashes during hydration. The DOM updates are comprehensive, updating both classList and data-theme attribute.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 36-36: contexts/theme.tsx#L36
Added line #L36 was not covered by tests

tailwind.config.js (1)

126-132: Proper theme configuration for DaisyUI

The DaisyUI configuration is now properly set up with:

  • Explicit dark theme specification
  • Base styling enabled
  • Logging disabled to reduce noise
  • Theme root properly set to :root

This helps ensure consistent theme application across the application.

pages/_app.tsx (1)

158-167: LGTM: Additional authentication methods

The new email and SMS authentication methods enhance accessibility while maintaining the existing theme context.

components/wallet.tsx (1)

Line range hint 53-95: Well-structured wallet content rendering with proper optimization.

The memoized rendering logic with clear visual feedback and consistent button states is well-implemented. The use of useMemo helps prevent unnecessary re-renders.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 38-38: components/wallet.tsx#L38
Added line #L38 was not covered by tests

components/react/sideNav.tsx (2)

106-110: Good improvement in theme state management.

Removing the redundant isdark state in favor of direct theme checks helps prevent hydration mismatches between server and client rendering.


198-202: Smooth theme toggle transition implementation.

The theme toggle transition is well-implemented with proper duration and easing.

Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

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

bun run build is throwing an error about metamask. Can you please fix?

@fmorency fmorency merged commit 97d0d27 into main Dec 13, 2024
7 of 8 checks passed
@fmorency fmorency deleted the chalabi/theme branch December 13, 2024 14:08
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.

Theme is broken for some users
2 participants