Skip to content

fix: resolve three script.js defects breaking the recommendation flow#437

Open
anshul23102 wants to merge 1 commit into
komalharshita:mainfrom
anshul23102:fix/script-three-defects-338
Open

fix: resolve three script.js defects breaking the recommendation flow#437
anshul23102 wants to merge 1 commit into
komalharshita:mainfrom
anshul23102:fix/script-three-defects-338

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

Summary [required]

Three independent defects in static/script.js combined to make the core recommendation flow completely broken. Project cards never appeared, a network failure would silently retry the API, and the loading spinner rendered incorrectly. All three issues are isolated to static/script.js with no changes to any other file.

Bug 1 (renderResults - cards never render, CRITICAL)
The outer if (!projects || projects.length === 0) block was never closed before the code that hides the empty state, shows the results grid, and runs projects.forEach. A nested duplicate if with an early return made those lines unreachable on every code path: when projects exist the outer condition is false so the whole block is skipped; when there are no projects the inner return fires first. The success path never executed. The fix collapses the duplicated conditions into a single guard with an early return for the empty case, leaving the success path unconditionally reachable when projects are present.

Bug 2 (duplicate fetch inside .catch(), CRITICAL)
The .catch() of the primary fetch("/api/recommend", ...) contained a full second fetch call with a re-declared payload. On any network error the second request fired and then unconditionally displayed "Something went wrong" regardless of its own response. The lines after the catch closure referenced data which was out of scope - unreachable dead code. The fix removes the entire duplicate fetch block and the dead code, replacing them with a lean .catch that calls setLoadingState(false), shows the error message, and logs the error.

Bug 3 (spinner display value overwritten, MEDIUM)
btnLoading.style.display and btnLabel.style.display were each assigned twice in immediate succession inside setLoadingState. The correct "inline-flex" value for the spinner was immediately overwritten with "inline", breaking its flex-based alignment. The fix removes both duplicate assignments, keeping only the first correct line for each element.

Related Issue [required]

Closes #338

Type of Change [required]

  • Bug fix — resolves a broken behaviour

What Was Changed [required]

File Change made
static/script.js Fixed renderResults guard logic; removed duplicate fetch from .catch(); removed duplicate display assignments from setLoadingState

How to Test This PR [required]

  1. Clone this branch: git checkout fix/script-three-defects-338
  2. Install dependencies: pip install -r requirements.txt
  3. Run the app: python app.py
  4. Open http://127.0.0.1:5000 and open the browser developer console (F12).
  5. Fill in the form (e.g. Python / Beginner / Data / Low) and click Generate My Projects.
  6. Confirm project cards appear in the results grid and no errors appear in the console.
  7. In DevTools Network tab, simulate offline mode and submit the form again. Confirm exactly one request fires and the error message appears without a second request.
  8. Confirm the loading spinner is correctly centred while the request is in flight.
  9. Run the tests: python tests/test_basic.py

Expected test output:

30 passed, 0 failed out of 30 tests

Test Results [required]

  PASS  test_projects_json_loads
  PASS  test_each_project_has_required_fields
  PASS  test_find_project_by_id_found
  PASS  test_find_project_by_id_missing
  PASS  test_parse_skills_basic
  PASS  test_parse_skills_empty_string
  PASS  test_parse_skills_single_entry
  PASS  test_score_single_project_full_match
  PASS  test_score_single_project_no_match
  PASS  test_get_recommendations_returns_results
  PASS  test_get_recommendations_max_three
  PASS  test_get_recommendations_no_match_returns_empty
  PASS  test_get_recommendations_result_format
  PASS  test_validate_all_valid
  PASS  test_validate_missing_skills
  PASS  test_validate_missing_level
  PASS  test_validate_missing_interest
  PASS  test_validate_missing_time
  PASS  test_validate_all_missing
  PASS  test_home_route
  PASS  test_recommend_api_valid
  PASS  test_recommend_api_missing_field
  PASS  test_recommend_api_empty_body
  PASS  test_project_detail_found
  PASS  test_project_detail_not_found
  PASS  test_internal_server_error_page
  PASS  test_view_code_found
  PASS  test_download_code_found
  PASS  test_health_check
  PASS  test_scoring_weights_has_all_keys

30 passed, 0 failed out of 30 tests

Self-Review Checklist [required]

  • I have read CONTRIBUTING.md and followed all guidelines
  • My branch name follows the convention: feat/, fix/, docs/, data/, style/, test/
  • I have run python tests/test_basic.py and all tests pass
  • I have not introduced any print() or console.log() debug statements
  • I have not modified files outside the scope of the linked issue
  • Code uses var declarations and ES5-compatible patterns per the project JS style guide

Notes for Reviewer

This PR is a net deletion of 45 lines. No new logic was introduced; the fix restores the code to match what the surrounding comments and function docstrings describe as intended behaviour. Each of the three bugs is independently reproducible using the steps in the issue.

…malharshita#338)

Bug 1 (renderResults - cards never render):
The outer if(!projects) block was never closed before the success-path
code that hides the empty state, shows the grid, and runs forEach. A
nested duplicate if with an early return made those lines unreachable on
every code path. Removed the duplicate inner if and all repeated display
assignments, added a single clean early return, and moved the success
path to execute after the guard.

Bug 2 (duplicate fetch on error):
The .catch() handler contained a full second fetch("/api/recommend", ...)
call with a re-declared payload. On a network error the second request
fired and unconditionally showed "Something went wrong" regardless of its
own response. Lines after the catch closure referenced data which was out
of scope - dead code that never ran. Removed the entire duplicate fetch
block and the dead code; replaced them with a lean .catch that only calls
setLoadingState(false), displays the error message, and logs the error.

Bug 3 (spinner display overwritten):
btnLoading.style.display was assigned twice in immediate succession.
The correct "inline-flex" value on the first line was immediately
overwritten with "inline", breaking the spinner's flex alignment. Same
double-assignment applied to btnLabel. Removed both duplicate lines,
keeping only the first correct assignment for each element.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

@anshul23102 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Three script.js defects — recommendation cards never render, duplicate fetch on error, spinner display overwrite

1 participant