fix: improve Code tab contrast in light mode - #207
Conversation
WalkthroughThe PR updates Playground Preview/Code tab contrast classes and refactors SocialShareButton container resolution and analytics error warnings to use debug-gated static logging. ChangesPlayground tab styling
SocialShareButton debug plumbing
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/social-share-button.js
| 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; |
There was a problem hiding this comment.
🎯 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); |
There was a problem hiding this comment.
🎯 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()}')
PYRepository: 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}')
PYRepository: 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.
| 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
| /** | ||
| * 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); |
There was a problem hiding this comment.
📐 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.
| /** | |
| * 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
|
@afzalansari12 do fix the Code Rabbit changes |
Fixes #206
The "Code" tab label and its separator had a hardcoded
text-whiteclass 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 hoverstates) so the label is visible in both themes, consistent with the
dark:pattern used elsewhere in this file.Summary by CodeRabbit