Skip to content

feat: implement system-based and toggleable dark mode closes #26#4161

Open
anjalikumari45 wants to merge 1 commit into
anurag3407:mainfrom
anjalikumari45:feature/dark-mode-implementation
Open

feat: implement system-based and toggleable dark mode closes #26#4161
anjalikumari45 wants to merge 1 commit into
anurag3407:mainfrom
anjalikumari45:feature/dark-mode-implementation

Conversation

@anjalikumari45

@anjalikumari45 anjalikumari45 commented Jun 17, 2026

Copy link
Copy Markdown

User description

Description

Implemented a comprehensive system-based and user-toggleable Dark Mode system using TailwindCSS 4 and React Context.

Key changes include:

  • Created a custom ThemeContext provider to manage and synchronize theme state across light, dark, and system preference states.
  • Persisted user preferences using localStorage to ensure consistency across active sessions.
  • Added event listeners to naturally track and adapt to native OS/system theme changes dynamically when the "system" preference is selected.
  • Configured tailwind.config.js to utilize the class strategy for toggling themes via the root DOM element.
  • Developed a semantic, reusable ThemeToggle component to allow immediate switching between views.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Other (describe)

Related Issue

Fixes #26

Testing

  • Unit tests pass
  • Tested Locally
  • New tests added

Screenshots (MANDATORY for UI/UX changes)

  • Attached Screenshots or Screen Recordings (showing before and after)

(Note: Please drag and drop your local before/after screenshots directly here in the GitHub browser window before hitting submit)

Checklist

  • Code follows project style guidelines
  • Self-reviewed my code
  • Added comments where necessary
  • Updated documentation
  • No new warnings generated

CodeAnt-AI Description

Add system-based and user-selectable dark mode

What Changed

  • Users can now switch between light, dark, and system theme settings
  • The app follows the device theme automatically when system mode is selected
  • Theme choice is saved across visits so the selected appearance stays in place
  • The theme switcher now shows a simple, visible dropdown with light/dark styling

Impact

✅ Easier theme switching
✅ Matches device appearance automatically
✅ Theme preference stays saved between visits

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

@anjalikumari45 is attempting to deploy a commit to the Anurag Mishra's projects Team on Vercel.

A member of the Team first needs to authorize it.

@codeant-ai

codeant-ai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@anjalikumari45, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 22 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbb71450-b102-4626-baeb-becc6a650f8f

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9c7ef and f8eab5f.

📒 Files selected for processing (3)
  • src/components/ThemeToggle.js
  • src/context/ThemeContext.js
  • tailwind.config.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Jun 17, 2026

const ThemeContext = createContext();

export const ThemeProvider = ({ children }) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: This provider is added under the repository root src/, but the running app is built from frontend/src and already uses frontend/src/context/ThemeProvider. As a result, this new theme system is never mounted in the actual application, so the feature will not work at runtime. Move this implementation into the frontend app tree or wire the frontend entrypoint to this provider. [incomplete implementation]

Severity Level: Major ⚠️
- ❌ New `src` ThemeProvider never affects the built frontend.
- ⚠️ Dark-mode changes in `src` tree never reach users.
Steps of Reproduction ✅
1. From the repo root, open `package.json` at `/workspace/career-pilot/package.json:1-9`
and observe the `build` script: `"build": "npm run build --prefix frontend"`, which builds
only the `frontend/` project.

2. In the frontend app, `frontend/src/main.jsx:1-8` renders `<App />` as the React root
and does not import anything from the top-level `src/` directory.

3. In `frontend/src/App.jsx:17-21` and `frontend/src/App.jsx:496-504`, `App` imports
`ThemeProvider` from `'./context/ThemeProvider'` and wraps the application tree with this
`ThemeProvider`, which is implemented in `frontend/src/context/ThemeProvider.jsx:12-54`.

4. The newly added `ThemeProvider` in `src/context/ThemeContext.js:5-37` is only
referenced by `src/components/ThemeToggle.js:1-5` and is never imported anywhere under
`frontend/src/` (verified via Grep results), so when you run or build the app via the
documented scripts, this new provider is never mounted and any behavior defined here has
no effect at runtime.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/context/ThemeContext.js
**Line:** 5:5
**Comment:**
	*Incomplete Implementation: This provider is added under the repository root `src/`, but the running app is built from `frontend/src` and already uses `frontend/src/context/ThemeProvider`. As a result, this new theme system is never mounted in the actual application, so the feature will not work at runtime. Move this implementation into the frontend app tree or wire the frontend entrypoint to this provider.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +6 to +24
const [theme, setTheme] = useState(() => {
return localStorage.getItem('theme') || 'system';
});

useEffect(() => {
const root = window.document.documentElement;
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

const applyTheme = () => {
root.classList.remove('light', 'dark');
if (theme === 'dark' || (theme === 'system' && mediaQuery.matches)) {
root.classList.add('dark');
} else {
root.classList.add('light');
}
};

applyTheme();
localStorage.setItem('theme', theme);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: localStorage is accessed directly without any environment or error guard, which can throw during render/effect in environments where storage is unavailable or blocked (e.g., strict privacy settings, non-browser execution paths), causing runtime failures. Guard access and fallback safely when storage read/write fails. [possible bug]

Severity Level: Major ⚠️
- ⚠️ ThemeProvider may crash in storage-restricted browser environments.
- ⚠️ Fails when used in non-browser or SSR executions.
- ⚠️ Inconsistent with guarded frontend ThemeProvider implementation.
Steps of Reproduction ✅
1. The new theme provider is defined in `src/context/ThemeContext.js:5-37`; when a React
tree uses `<ThemeProvider>` from this file as a wrapper, React executes the `useState`
initializer at lines 6-8: `return localStorage.getItem('theme') || 'system';`.

2. Because this initializer accesses `localStorage` directly, rendering `<ThemeProvider>`
in any non-browser environment (e.g., SSR or a Node-based test runner without
`localStorage`) will throw immediately at `src/context/ThemeContext.js:7` before the
component can render.

3. On the client, the `useEffect` at `src/context/ThemeContext.js:10-30` always calls
`localStorage.setItem('theme', theme);` at line 24 without try/catch; in browsers where
storage is disabled or throws (strict privacy mode, quota-exceeded, etc.), this will cause
the effect to throw and crash the React subtree.

4. The existing, actually-used frontend provider in
`frontend/src/context/ThemeProvider.jsx:13-35` shows the intended defensive pattern
(`typeof window === 'undefined'` checks and try/catch around `window.localStorage`),
confirming that the unguarded `localStorage` usage in `src/context/ThemeContext.js:6-8`
and `:24` is a robustness bug relative to the established implementation.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/context/ThemeContext.js
**Line:** 6:24
**Comment:**
	*Possible Bug: `localStorage` is accessed directly without any environment or error guard, which can throw during render/effect in environments where storage is unavailable or blocked (e.g., strict privacy settings, non-browser execution paths), causing runtime failures. Guard access and fallback safely when storage read/write fails.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

);
};

export const useTheme = () => useContext(ThemeContext);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The custom hook returns raw context without validating that a provider exists, so any consumer rendered outside the provider will get undefined and crash when destructuring theme values. Add an explicit guard that throws a clear error when used outside the provider. [null pointer]

Severity Level: Major ⚠️
- ⚠️ Using ThemeToggle outside provider causes hard-to-debug crash.
- ⚠️ Diverges from guarded `frontend` useTheme hook behavior.
Steps of Reproduction ✅
1. The custom hook is implemented in `src/context/ThemeContext.js:39` as `export const
useTheme = () => useContext(ThemeContext);` with no validation that a provider is present.

2. Component `ThemeToggle` at `src/components/ThemeToggle.js:4-5` calls `useTheme()` and
immediately destructures `{ theme, setTheme }` from the hook return value.

3. If a consuming app renders `<ThemeToggle />` without wrapping it in `<ThemeProvider>`
from `src/context/ThemeContext.js:5-37`, `useContext(ThemeContext)` returns `undefined`
because `ThemeContext` was created with no default value (`createContext()` at line 3).

4. Destructuring `{ theme, setTheme }` from `undefined` in
`src/components/ThemeToggle.js:5` will throw a TypeError at runtime, producing a vague
"cannot destructure property 'theme' of 'undefined'" error instead of the clear,
intentional error used in the existing frontend hook `frontend/src/hooks/useTheme.js:8-13`
(`throw new Error('useTheme must be used within a ThemeProvider');`).

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/context/ThemeContext.js
**Line:** 39:39
**Comment:**
	*Null Pointer: The custom hook returns raw context without validating that a provider exists, so any consumer rendered outside the provider will get `undefined` and crash when destructuring theme values. Add an explicit guard that throws a clear error when used outside the provider.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Frontend] Dark Mode Implementation

1 participant