Skip to content

fix: improve Code tab contrast in light mode - #207

Open
afzalansari12 wants to merge 2 commits into
AOSSIE-Org:mainfrom
afzalansari12:fix/206-light-mode-code-tab-contrast
Open

fix: improve Code tab contrast in light mode#207
afzalansari12 wants to merge 2 commits into
AOSSIE-Org:mainfrom
afzalansari12:fix/206-light-mode-code-tab-contrast

Conversation

@afzalansari12

@afzalansari12 afzalansari12 commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #206

The "Code" tab label and its separator had a hardcoded text-white
class with no light-mode fallback, making it invisible against the
light background in light mode.

Fix: added text-neutral-900 dark:text-white (and matching hover
states) so the label is visible in both themes, consistent with the
dark: pattern used elsewhere in this file.

Summary by CodeRabbit

  • Style
    • Updated the Playground’s “Preview”/“Code” tab switcher with more consistent neutral colors and improved dark-mode hover states.
  • Bug Fixes
    • Improved Social Share Button reliability by safely handling environments without a DOM and reducing unnecessary console warnings (when not debugging), helping prevent related runtime issues.

@github-actions github-actions Bot added bug Something isn't working frontend Changes to frontend code javascript JavaScript/TypeScript code changes size/XS Extra small PR (≤10 lines changed) first-time-contributor First PR of an external contributor needs-review labels Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR updates Playground Preview/Code tab contrast classes and refactors SocialShareButton container resolution and analytics error warnings to use debug-gated static logging.

Changes

Playground tab styling

Layer / File(s) Summary
Update tab contrast classes
landing-page/src/components/Playground.tsx
The separator and Code tab now use neutral text colors with dark-mode-aware hover colors.

SocialShareButton debug plumbing

Layer / File(s) Summary
Refactor debug warning handling
src/social-share-button.js
Container selector failures and analytics delivery errors now use the static _debugWarn helper with explicit debug gating.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: Typescript Lang

Suggested reviewers: kpj2006

Poem

I’m a bunny with code in my paws,
Making light-mode letters obey contrast laws.
Debug warnings now hop when true,
Through containers and analytics too—
Clean tabs and calmer logs ensue!

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes SocialShareButton analytics/debug plumbing, which is unrelated to the Code tab contrast bug. Move the SocialShareButton changes to a separate PR and keep this one focused on the Code tab styling fix.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: improving the Code tab’s light-mode contrast.
Linked Issues check ✅ Passed The Code tab styling change addresses the reported low-contrast visibility issue in light mode.
✨ 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.

@github-actions github-actions Bot added size/S Small PR (11-50 lines changed) and removed size/XS Extra small PR (≤10 lines changed) labels Jul 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/social-share-button.js`:
- Around line 746-755: Replace the JSDoc block immediately above
SocialShareButton._debugWarn with a concise inline comment describing that it
logs warnings only when debug mode is enabled. Preserve the method’s parameters,
behavior, and console warning unchanged.
- Around line 735-743: Update the call site that invokes
SocialShareButton._resolveContainer to pass options.debug as the second
argument, preserving debug warnings for invalid container selectors while
leaving _resolveContainer’s existing behavior unchanged.
- Line 742: Update the _debugWarn call in the invalid container-selector
handling to pass the caught querySelector exception as the error argument,
rather than raw. Preserve the existing warning message and ensure the selector
error remains available to _debugWarn for logging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8c564cd7-21b2-41fd-922a-78930ebe0fbd

📥 Commits

Reviewing files that changed from the base of the PR and between 5edd391 and 592a13c.

📒 Files selected for processing (1)
  • src/social-share-button.js

Comment on lines +735 to +743
static _resolveContainer(raw, debug) {
if (!raw) return null;
if (typeof document === "undefined") return null;
return typeof raw === "string" ? document.querySelector(raw) : raw;
}

// Returns the cached host container element, or null.
_getContainer() {
return this._containerEl || null;
if (typeof raw !== "string") return raw;
try {
return document.querySelector(raw);
} catch (error) {
SocialShareButton._debugWarn(debug, "Invalid container selector:", raw, error);
return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Pass the debug flag into _resolveContainer.

Line 13 still calls _resolveContainer(options.container) without options.debug, so invalid selectors are silently suppressed even when debug mode is enabled.

Proposed fix
-    const containerEl = SocialShareButton._resolveContainer(options.container);
+    const containerEl = SocialShareButton._resolveContainer(
+      options.container,
+      options.debug
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/social-share-button.js` around lines 735 - 743, Update the call site that
invokes SocialShareButton._resolveContainer to pass options.debug as the second
argument, preserving debug warnings for invalid container selectors while
leaving _resolveContainer’s existing behavior unchanged.

try {
return document.querySelector(raw);
} catch (error) {
SocialShareButton._debugWarn(debug, "Invalid container selector:", raw, error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file found =="
git ls-files | grep -F 'src/social-share-button.js' || true

echo "== outline around relevant function/call =="
if [ -f src/social-share-button.js ]; then
  wc -l src/social-share-button.js
  ast-grep outline src/social-share-button.js --view compact | sed -n '1,200p' || true
  echo "== _debugWarn definition/usages =="
  rg -n "_debugWarn|Invalid container selector|try\\s*\\{|catch\\s*\\([^)]*error" src/social-share-button.js
  echo "== relevant lines 700-760 =="
  sed -n '700,760p' src/social-share-button.js | nl -ba -v700
fi

echo "== programmatic source inspection =="
python3 - <<'PY'
from pathlib import Path
import re

p = Path('src/social-share-button.js')
if not p.exists():
    print('missing src/social-share-button.js')
    raise SystemExit(0)
s = p.read_text()

# Locate function body for _debugWarn and calls with 4 args.
for m in re.finditer(r'(?:static\s+)?_debugWarn\s*\(([^)]*)\)\s*\{', s):
    params = m.group(1).strip()
    start = m.end()
    brace = 1
    i = start
    while i < len(s) and brace:
        if s[i] == '{': brace += 1
        elif s[i] == '}': brace -= 1
        i += 1
    print('_debug_WARN declaration params:', params)
    print('_debug_warn body:', '\n'.join(s[start:i-1].splitlines()[:20]))

for i,line in enumerate(s.splitlines(),1):
    if '_debugWarn(' in line and line.count('Error') > 1 or (line.count(',') >= 4 and '_debugWarn' in line):
        print(f'line {i}: {line.strip()}')
PY

Repository: AOSSIE-Org/SocialShareButton

Length of output: 1033


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== line 700-760 =="
sed -n '700,760p' src/social-share-button.js

echo "== line 750-795 =="
sed -n '750,795p' src/social-share-button.js

echo "== ast outline for static methods =="
ast-grep outline src/social-share-button.js --view signatures | sed -n '1,240p' || true

echo "== all _debugWarn call argument counts =="
python3 - <<'PY'
from pathlib import Path
import re
p = Path('src/social-share-button.js')
for i,line in enumerate(p.read_text().splitlines(),1):
    if '_debugWarn(' in line:
        # Remove line continuation/spans and count _debugWarn call args conservatively
        text = ''.join(line)
        if '(' in text:
            args = []
            depth=0
            in_str=False
            esc=False
            start=text.index('_debugWarn(')+len('_debugWarn(')
            for c in text[start:]:
                if in_str:
                    if c=='\\' and not esc:
                        esc=True; continue
                    if c=='"': in_str=False
                    esc=False
                    continue
                if c in ('"',"'") and c not in '([{':
                    in_str=True
                elif c in '([{': depth += 1
                elif c in ')]}': depth -= 1
                elif c in ',\n' and depth==0:
                    args.append('(')
            else:
                args.append('(')
            print(f'{i}: {text.strip()} | args={len(args)-1}')
PY

Repository: AOSSIE-Org/SocialShareButton

Length of output: 5144


Preserve the caught selector error.

_debugWarn(debug, message, err) logs exactly message and err; passing raw as the third argument logs the selector instead of the querySelector exception.

Proposed fix
-      SocialShareButton._debugWarn(debug, "Invalid container selector:", raw, error);
+      SocialShareButton._debugWarn(
+        debug,
+        `Invalid container selector: ${raw}`,
+        error
+      );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SocialShareButton._debugWarn(debug, "Invalid container selector:", raw, error);
SocialShareButton._debugWarn(
debug,
`Invalid container selector: ${raw}`,
error
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/social-share-button.js` at line 742, Update the _debugWarn call in the
invalid container-selector handling to pass the caught querySelector exception
as the error argument, rather than raw. Preserve the existing warning message
and ensure the selector error remains available to _debugWarn for logging.

Source: Learnings

Comment on lines +746 to +755
/**
* Logs warnings only when debug mode is enabled.
* @param {boolean} debug - Whether debug mode is on.
* @param {string} message - Description of the failed path.
* @param {Error} [err] - The caught error instance, if any.
*/
_debugWarn(message, err) {
// _debugWarn: emit analytics warnings only in debug mode for visibility.
if (!this.options.debug) return;
// eslint-disable-next-line no-console
console.warn("[SocialShareButton Analytics]", message, err);
}
static _debugWarn(debug, message, err) {
if (!debug) return;
// eslint-disable-next-line no-console
console.warn("[SocialShareButton]", message, err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use a concise inline comment for _debugWarn.

The new JSDoc block violates the src/**/*.js path instruction requiring minimal inline comments.

Proposed fix
-/**
- * Logs warnings only when debug mode is enabled.
- * `@param` {boolean} debug - Whether debug mode is on.
- * `@param` {string} message - Description of the failed path.
- * `@param` {Error} [err] - The caught error instance, if any.
- */
+// Log warnings only when debug mode is enabled.
 static _debugWarn(debug, message, err) {

As per path instructions, modified methods must use minimal inline comments rather than JSDoc.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Logs warnings only when debug mode is enabled.
* @param {boolean} debug - Whether debug mode is on.
* @param {string} message - Description of the failed path.
* @param {Error} [err] - The caught error instance, if any.
*/
_debugWarn(message, err) {
// _debugWarn: emit analytics warnings only in debug mode for visibility.
if (!this.options.debug) return;
// eslint-disable-next-line no-console
console.warn("[SocialShareButton Analytics]", message, err);
}
static _debugWarn(debug, message, err) {
if (!debug) return;
// eslint-disable-next-line no-console
console.warn("[SocialShareButton]", message, err);
// Log warnings only when debug mode is enabled.
static _debugWarn(debug, message, err) {
if (!debug) return;
// eslint-disable-next-line no-console
console.warn("[SocialShareButton]", message, err);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/social-share-button.js` around lines 746 - 755, Replace the JSDoc block
immediately above SocialShareButton._debugWarn with a concise inline comment
describing that it logs warnings only when debug mode is enabled. Preserve the
method’s parameters, behavior, and console warning unchanged.

Source: Path instructions

@PrithvijitBose

Copy link
Copy Markdown
Contributor

@afzalansari12 do fix the Code Rabbit changes

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

Labels

bug Something isn't working first-time-contributor First PR of an external contributor frontend Changes to frontend code javascript JavaScript/TypeScript code changes needs-review size/S Small PR (11-50 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: "Code" tab text is not visible in Light Mode

2 participants