Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions landing-page/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function Playground() {

<div className="flex items-center justify-center gap-6 mb-12">
<button className="text-[#FFCC00] font-bold text-xl font-serif">Preview</button>
<span className="text-white font-bold text-xl">|</span>
<button className="text-white font-bold text-xl font-serif hover:text-neutral-300 transition-colors">Code</button>
<span className="text-neutral-900 dark:text-white font-bold text-xl">|</span>
<button className="text-neutral-900 dark:text-white font-bold text-xl font-serif hover:text-neutral-500 dark:hover:text-neutral-300 transition-colors">Code</button>
</div>

{/* The Output Mockup */}
Expand Down
43 changes: 22 additions & 21 deletions src/social-share-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,28 +732,29 @@
// ---------------------------------------------------------------------------

// Resolves a raw container value (string or Element) to a DOM Element, or null if absent/SSR.
static _resolveContainer(raw) {
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);

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

return null;
Comment on lines +735 to +743

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.

}
}

/**
* Logs analytics warnings only when debug mode is enabled.
* @param {string} message - Description of the failed analytics path.
* @param {Error} err - The caught error instance.
/**
* 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);
Comment on lines +746 to +755

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

}


/**
* Emits an analytics event through all configured delivery paths.
Expand Down Expand Up @@ -814,7 +815,7 @@
const el = this._getContainer();
(el || document).dispatchEvent(domEvent);
} catch (err) {
this._debugWarn("DOM event dispatch failed", err);
SocialShareButton._debugWarn(this.options.debug, message, err);

Check failure on line 818 in src/social-share-button.js

View workflow job for this annotation

GitHub Actions / lint

'message' is not defined
}
}

Expand All @@ -823,7 +824,7 @@
try {
this.options.onAnalytics(payload);
} catch (err) {
this._debugWarn("onAnalytics callback failed", err);
SocialShareButton._debugWarn(this.options.debug, message, err);

Check failure on line 827 in src/social-share-button.js

View workflow job for this annotation

GitHub Actions / lint

'message' is not defined
}
}

Expand All @@ -834,7 +835,7 @@
try {
plugin.track(payload);
} catch (err) {
this._debugWarn("plugin.track() failed", err);
SocialShareButton._debugWarn(this.options.debug, message, err);

Check failure on line 838 in src/social-share-button.js

View workflow job for this annotation

GitHub Actions / lint

'message' is not defined
}
}
}
Expand Down
Loading