fix(shop): repair duplicated initialization block that left shop.js unparsable - #1701
fix(shop): repair duplicated initialization block that left shop.js unparsable#1701MOHITKOURAV01 wants to merge 1 commit into
Conversation
🔍 Quality Gate Report✅ All quality gates passed!
|
|
Someone is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
🤖 AI Code Review🔴 Score: 50/100 | AI review unavailable at this time. Automated AI review — a human maintainer will also review. |
|
💡 Suggested reviewers based on relevant file history: @Aditya8369, @Pcmhacker-hero |
🟡 PR Health Score: 55/100This PR's health score is below the 75/100 threshold for a healthy label.
Improving these signals will help reviewers engage faster and raise your score. 💪 |
…nparsable The responsive refactor duplicated the tail of frontend/scripts/shop.js and interleaved the two copies. The result did not parse -- an unclosed arrow body, a second half-finished DOMContentLoaded registration, statements referring to a filterUrlParams no longer in scope, and an IntersectionObserver options object passed as the third argument to addEventListener. The browser answered with 'Unexpected end of input' and ran nothing at all on shop.html. Collapse the two back into the one handler the page needs, and restore the clear-filters behaviour the merge stranded: strip category/subcategory from the query string, rewrite the address bar, clear filters.megaCategory and filters.megaSubcategory, then re-run applyFilters. Add backend/tests/frontendScriptParse.test.js, which compiles every file under frontend/scripts with the script goal a <script> tag uses, and pins the shape of shop.js's initialization block so the duplication cannot come back green.
37e1dd5 to
faa44f6
Compare
🔍 Quality Gate Report✅ All quality gates passed!
|
🤖 AI Code Review🔴 Score: 50/100 | AI review unavailable at this time. Automated AI review — a human maintainer will also review. |
|
💡 Suggested reviewers based on relevant file history: @Aditya8369, @Pcmhacker-hero |
🟡 PR Health Score: 55/100This PR's health score is below the 75/100 threshold for a healthy label.
Improving these signals will help reviewers engage faster and raise your score. 💪 |
Closes #1696
What was wrong
frontend/scripts/shop.jsdid not parse.npm run check:syntaxwas red onmain:The responsive-design refactor duplicated the initialization block at the bottom of the file and then interleaved the two copies. The tail ended up with two
DOMContentLoadedregistrations: the first with an arrow body that is never closed and a clear-filters listener that lost its body and picked up{ rootMargin: "200px 0px" }— anIntersectionObserveroptions object belonging toobserveSentinel()— as its third argument; the second re-doing the same element lookups, stopping halfway through them, and running into orphaned fragments of the first handler's body that referenced afilterUrlParamsno longer in scope.A
SyntaxErroraborts the whole script, soshop.htmlhad no JavaScript: no product fetch, no filters, no sort, no infinite scroll, no search suggestions.What this does
Collapses the two blocks back into the single handler the page has always needed, reconstructed from
b8b934a^, and restores the clear-filters behaviour the merge stranded. That behaviour matters beyond tidiness: a shopper arriving from the mega menu carriescategory/subcategoryin the query string, andfilters.megaCategory/filters.megaSubcategoryare seeded from them. Resetting only the checkboxes leaves both in place, so the nextapplyFilters()re-applies the filter the button just cleared and a reload brings it back. The handler now strips the params, rewrites the address bar, clears the mega filters, and re-runs the query.Two small things kept from the reconstruction rather than the original:
handleCategorySelectreturns early when a card has nodata-category, instead of building a checkbox withvalue="undefined".addEventListeneroptions object is gone. The browser silently accepts it — it reads as an options bag with no recognised keys — which is why this only ever looked like a listener that was wired and was not.The call shape
The listener is written as the multi-line form:
not the compact
document.addEventListener("DOMContentLoaded", () => { ... });. That is not a style preference —tests/mergeScarRegression.test.jsalready pins it:That suite has been red on
mainsince the refactor. This makes itsparses,has exactly one DOMContentLoaded initialiserandcloses that listenercases green again.Guard
backend/tests/frontendScriptParse.test.jscompiles every file underfrontend/scriptswithvm.Script, the same parse goal a classic<script>tag and CommonJS use, retrying genuine ES modules the wayscripts/check-syntax.jsdoes. It then pins the shape of shop.js's init block: oneDOMContentLoadedregistration, one declaration offilterUrlParamswith no stranded uses, no observer options handed toaddEventListener, and all six steps of the clear-filters handler present.check:syntaxalready catches the parse failure, but it is a separate CI step; having it in the jest suite puts the failure next to the behaviour it breaks.Verification
Confirmed the guard is real by stashing the shop.js fix and re-running the new test against the broken file:
The pre-existing
tests/mergeScarRegression.test.jsgoes from three failures onmainto one:The one it still reports —
frontend/scripts/product-cards-home.js › declares the stock bindings its card template reads— is a different file and a separate defect from the same refactor, and is out of scope here.Also ran
check:assets,check:a11y,check:sitemap,check:bootandcheck:modules— all pass.CI note
Syntax check ✅ and Server boots ✅ — the two jobs that were red on
mainbecause of this file.Backend tests is still red, on suites this PR does not touch. All five already fail on
main:mergeScarRegressionproduct-cards-home.js › declares the stock bindings its card template readscartBulkSelectiondoes not put handlers on the global objectwishlistReadsp.is_active = 1missing from the queriesmigrationViewColumnsno two migrations claim the same versionfraudMonitoringQueuetakes the next free migration numberThis PR takes
mergeScarRegression'sfrontend/scripts/shop.jsblock from three failures to zero:The
Vercelcheck fails on every PR in this repository with "Authorization required to deploy" against thebhuvanshs-projectsteam, unrelated to any change.