Skip to content

Bugfix in cfg loading in settings_leds.htm#5701

Open
DedeHai wants to merge 6 commits into
wled:mainfrom
DedeHai:fix_cfg_load
Open

Bugfix in cfg loading in settings_leds.htm#5701
DedeHai wants to merge 6 commits into
wled:mainfrom
DedeHai:fix_cfg_load

Conversation

@DedeHai

@DedeHai DedeHai commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

a const can not be incremented, it throws an error.

remove dead code.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Refined LED count and memory threshold behavior so submission is consistently blocked at the highest limit, while the higher warning level shows only the reboot recommendation.
    • Improved LED output form behavior for more consistent per-output labeling and limit calculations across multiple outputs.
    • Updated WiFi scan UI so SSID options are no longer cleared before refresh, preventing disappearing/duplicated entries during scans.
  • Chores

    • Made small internal cleanup in the LED settings UI and configuration template handling for maintainability.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ab0f7fbf-1d55-4232-820b-412119e667da

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Walkthrough

settings_leds.htm updates trySubmit() validation messaging, removes sameType tracking in UI(), keeps the dropdown refresh comment, and changes a loadCfg() loop index declaration to let.

Changes

LED settings update

Layer / File(s) Summary
Form validation branch
wled00/data/settings_leds.htm
trySubmit() changes the bquot warning branch message composition and return behavior before the ABL/PPL checks.
UI input metadata
wled00/data/settings_leds.htm
UI() no longer tracks sameType during LED output iteration, and the second updateTypeDropdowns() call keeps its inline comment.
Loop variable declaration
wled00/data/settings_leds.htm
loadCfg() now declares the LED-output removal loop index with let while still calling addLEDs(-1) repeatedly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wled/WLED#4928: Also changes trySubmit() validation and the bquot-based LED memory warning flow in wled00/data/settings_leds.htm.
  • wled/WLED#5026: Also touches trySubmit() submission validation in wled00/data/settings_leds.htm.

Suggested labels

Awaiting testing

Suggested reviewers

  • netmindz
  • softhack007
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: a cfg-loading bug fix in settings_leds.htm.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@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: 1

🤖 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 `@wled00/data/settings_leds.htm`:
- Line 163: The high-`bquot` branch in the settings UI currently only assigns a
`msg` string and no longer triggers the warning flow, so restore the existing
confirmation/alert handling in the `settings_leds.htm` logic where `bquot > 80`
is checked. Update that branch so the message is actually presented to the user
and the previous high-memory warning behavior is preserved, instead of leaving
an unused `msg` variable in place.
🪄 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: CHILL

Plan: Pro

Run ID: 48929170-7219-4dd2-8751-26da4487690b

📥 Commits

Reviewing files that changed from the base of the PR and between 656b620 and 6c52dce.

📒 Files selected for processing (1)
  • wled00/data/settings_leds.htm

Comment thread wled00/data/settings_leds.htm Outdated
@DedeHai

DedeHai commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai please thoroughly check all htm files in the /data folder for other such small bugs and dead or unreachable code.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Find data directory and list .htm files =="
fd -t d '^data$' .
echo
fd -e htm . data || true

echo
echo "== AST outline for each .htm file in data =="
for f in $(fd -e htm . data | sort); do
  echo
  echo "---- $f ----"
  ast-grep outline "$f" --view expanded || true
done

echo
echo "== Search for suspicious patterns in data/*.htm =="
rg -n --glob 'data/*.htm' --glob 'data/**/*.htm' \
  -e '\bconst\s+[A-Za-z_$][A-Za-z0-9_$]*\s*=.*\+\+|--' \
  -e '\b(let|const|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b.*\n.*\b\2\b' \
  -e '\bif\s*\(\s*false\s*\)' \
  -e '\bif\s*\(\s*true\s*\)' \
  -e '\bwhile\s*\(\s*false\s*\)' \
  -e '\bfor\s*\(\s*;\s*false\s*;' \
  -e '\breturn\s*;?[[:space:]]*$' \
  -e '\bcontinue\s*;?[[:space:]]*$' \
  -e '\bbreak\s*;?[[:space:]]*$' \
  -e '\bTODO\b|\bFIXME\b|\bXXX\b' \
  -e 'else if\s*\([^)]*\)\s*{\s*}\s*' \
  -e '\bif\s*\([^)]*\)\s*{\s*}\s*else' \
  -e '\b===?\s*undefined\b|\b!==?\s*undefined\b' \
  data || true

echo
echo "== Search for duplicate conditional ladders / repeated thresholds =="
rg -n -C2 --glob 'data/*.htm' --glob 'data/**/*.htm' \
  -e 'else if\s*\(' \
  -e 'if\s*\(' \
  data | sed -n '1,260p'

echo
echo "== Search for functions and vars that may be unused in data/*.htm =="
python - <<'PY'
import re, subprocess, json, os, sys
files = subprocess.check_output(["fd","-e","htm",".","data"]).decode().splitlines()
decl_pat = re.compile(r'\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(')
var_pat = re.compile(r'\b(?:let|const|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b')
for f in files:
    txt = open(f, 'r', encoding='utf-8', errors='ignore').read()
    funcs = decl_pat.findall(txt)
    vars_ = var_pat.findall(txt)
    findings = []
    for name in funcs:
        count = len(re.findall(r'\b%s\b' % re.escape(name), txt))
        if count == 1:
            findings.append(("function", name, count))
    for name in vars_:
        count = len(re.findall(r'\b%s\b' % re.escape(name), txt))
        if count == 1 and name not in {"i","j","k","d","e","v","x","y"}:
            findings.append(("var", name, count))
    if findings:
        print(f"--- {f} ---")
        for kind, name, count in findings[:40]:
            print(f"{kind}\t{name}\t{count}")
PY

echo
echo "== Read key slices from each data/*.htm file (first 260 lines) =="
for f in $(fd -e htm . data | sort); do
  echo
  echo "---- $f : lines 1-260 ----"
  sed -n '1,260p' "$f"
done

Length of output: 3914


🏁 Script executed:

#!/bin/bash
set -euo pipefail

root="wled00/data"

echo "== List .htm files under $root =="
fd -e htm . "$root" | sort

echo
echo "== Suspicious pattern scan in $root/*.htm =="
rg -n -C2 --pcre2 \
  -g '*.htm' "$root" \
  -e '\bif\s*\(\s*false\s*\)' \
  -e '\bif\s*\(\s*true\s*\)' \
  -e '\bwhile\s*\(\s*false\s*\)' \
  -e '\bfor\s*\(\s*;\s*false\s*;' \
  -e '\bTODO\b|\bFIXME\b|\bXXX\b' \
  -e '\b(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=.*(?:\+\+|--)' \
  -e '\b(?:return|break|continue)\s*;[ \t]*$' \
  -e 'else if\s*\([^)]*\)\s*{\s*}' \
  -e '\bif\s*\([^)]*\)\s*{\s*}\s*else' \
  -e '\b===?\s*undefined\b|\b!==?\s*undefined\b' || true

echo
echo "== Count conditionals and function declarations per file =="
for f in $(fd -e htm . "$root" | sort); do
  printf '\n-- %s --\n' "$f"
  printf 'if/else count: '
  rg -o '\bif\s*\(|\belse\s+if\s*\(' "$f" | wc -l
  printf 'function count: '
  rg -o '\bfunction\s+[A-Za-z_$][A-Za-z0-9_$]*\s*\(' "$f" | wc -l
done

echo
echo "== Possible single-use function declarations =="
python - <<'PY'
import re, subprocess
files = subprocess.check_output(["fd","-e","htm",".","wled00/data"]).decode().splitlines()
decl_pat = re.compile(r'\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(')
for f in sorted(files):
    txt = open(f, 'r', encoding='utf-8', errors='ignore').read()
    names = decl_pat.findall(txt)
    hits = []
    for name in names:
        count = len(re.findall(r'\b%s\b' % re.escape(name), txt))
        if count == 1:
            hits.append(name)
    if hits:
        print(f"--- {f} ---")
        for name in hits:
            print(name)
PY

echo
echo "== Full numbered contents of each .htm file =="
for f in $(fd -e htm . "$root" | sort); do
  echo
  echo "---- $f ----"
  nl -ba "$f"
done

Length of output: 57510


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Context around candidate hotspots =="

for spec in \
  "wled00/data/settings_wifi.htm:58:126" \
  "wled00/data/settings_2D.htm:96:120" \
  "wled00/data/settings_ui.htm:70:95" \
  "wled00/data/settings_leds.htm:750:780" \
  "wled00/data/update.htm:40:110" \
  "wled00/data/settings_dmx.htm:50:62"
do
  file="${spec%%:*}"
  rest="${spec#*:}"
  start="${rest%%:*}"
  end="${rest##*:}"
  echo
  echo "---- $file : lines $start-$end ----"
  sed -n "${start},${end}p" "$file" | nl -ba -v "$start"
done

echo
echo "== Possible single-use function declarations (safe run) =="
python - <<'PY'
import re, subprocess
files = subprocess.check_output(["fd","-e","htm",".","wled00/data"]).decode().splitlines()
decl_pat = re.compile(r'\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(')
for f in sorted(files):
    txt = open(f, 'r', encoding='utf-8', errors='ignore').read()
    hits = []
    for name in decl_pat.findall(txt):
        count = len(re.findall(r'\b%s\b' % re.escape(name), txt))
        if count == 1:
            hits.append(name)
    if hits:
        print(f"--- {f} ---")
        for name in hits[:30]:
            print(name)
PY

echo
echo "== Search for commented-out code blocks in data/*.htm =="
rg -n -C1 --glob '*.htm' '^\s*//\s*(if|for|while|return|let|const|var|function)\b|/\*\s*(if|for|while|return|let|const|var|function)\b' wled00/data || true

echo
echo "== Search for duplicated branch conditions in settings_leds.htm and settings_wifi.htm =="
rg -n -C2 --pcre2 '(if|else if)\s*\(([^)]*)\)' wled00/data/settings_leds.htm wled00/data/settings_wifi.htm || true

Length of output: 2084


🏁 Script executed:

#!/bin/bash
set -u

echo "== Context around candidate hotspots =="

show_slice() {
  file="$1"
  start="$2"
  end="$3"
  echo
  echo "---- $file : lines $start-$end ----"
  awk -v s="$start" -v e="$end" 'NR>=s && NR<=e { printf "%6d  %s\n", NR, $0 }' "$file" || true
}

show_slice "wled00/data/settings_wifi.htm" 58 126
show_slice "wled00/data/settings_2D.htm" 96 120
show_slice "wled00/data/settings_ui.htm" 70 95
show_slice "wled00/data/settings_leds.htm" 750 780
show_slice "wled00/data/update.htm" 40 110
show_slice "wled00/data/settings_dmx.htm" 50 62

echo
echo "== Possible single-use function declarations (safe run) =="
python - <<'PY'
import re, subprocess
files = subprocess.check_output(["fd","-e","htm",".","wled00/data"]).decode().splitlines()
decl_pat = re.compile(r'\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(')
for f in sorted(files):
    txt = open(f, 'r', encoding='utf-8', errors='ignore').read()
    hits = []
    seen = set()
    for name in decl_pat.findall(txt):
        if name in seen:
            continue
        seen.add(name)
        count = len(re.findall(r'\b%s\b' % re.escape(name), txt))
        if count == 1:
            hits.append(name)
    if hits:
        print(f"--- {f} ---")
        for name in hits[:30]:
            print(name)
PY

echo
echo "== Search for commented-out code blocks in data/*.htm =="
rg -n -C1 --glob '*.htm' '^\s*//\s*(if|for|while|return|let|const|var|function)\b|/\*\s*(if|for|while|return|let|const|var|function)\b' wled00/data || true

Length of output: 15006



@DedeHai I did a broader pass over the .htm files in wled00/data and found a couple of concrete issues plus a few cleanup-only leftovers.

Actionable findings:

  • wled00/data/settings_wifi.htm, Line 68-Line 70: select is created fresh on Line 62, so the loop clearing select.children is dead/useless. If this were ever reused on a non-empty live collection, the forward-removal pattern could also skip nodes. This loop can just be removed.
  • wled00/data/settings_2D.htm, Line 109: if (j*i < maxPanels) addPanel(p); looks wrong. The real panel index is p, but the guard uses j*i, which stops matching the number of created panels once both indices grow. This can under-create panel inputs for some layouts. It likely should use p < maxPanels, or the guard can be removed entirely if the dimensions are already capped before the loop.
  • wled00/data/settings_ui.htm, Line 82: if (i.indexOf('LABEL') > 0) continue; is a bit too loose and also misses the exact key "LABEL". If the intent is to skip only helper label keys, a suffix/exact check would be safer.

Cleanup-only / stale code:

  • wled00/data/settings_dmx.htm, Line 56 still has a TODO and meme placeholder heading text.
  • Commented-out code remains in:
    • wled00/data/settings_um.htm, Line 83
    • wled00/data/settings_pininfo.htm, Line 41
    • wled00/data/settings_leds.htm, Line 884
    • wled00/data/pixelforge/pixelforge.htm, Line 581-Line 582

I did not find another obvious const-increment style bug in this pass, and I’d treat most of the “single-use function” hits as non-actionable because several pages rely on inline handlers or dynamic references.

I’ll leave focused review comments for the actionable ones.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants