{"record":{"id":"0e4a17c4d46a7dc3","repo":"Freika/dawarich","slug":"maps-controller-or-placesmanager-not-found","errorCode":null,"errorMessage":"Maps controller or placesManager not found","messagePattern":"Maps controller or placesManager not found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/javascript/controllers/places_filter_controller.js","lineNumber":12,"sourceCode":"import { Controller } from \"@hotwired/stimulus\"\n\nexport default class extends Controller {\n  connect() {\n    console.log(\"Places filter controller connected\")\n  }\n\n  filterPlaces(_event) {\n    // Get reference to the maps controller's placesManager\n    const mapsController = window.mapsController\n    if (!mapsController || !mapsController.placesManager) {\n      console.warn(\"Maps controller or placesManager not found\")\n      return\n    }\n\n    // Collect all checked tag IDs\n    const checkboxes = this.element.querySelectorAll(\n      'input[type=\"checkbox\"][data-tag-id]',\n    )\n    const selectedTagIds = Array.from(checkboxes)\n      .filter((cb) => cb.checked)\n      .map((cb) => parseInt(cb.dataset.tagId, 10))\n\n    console.log(\"Filtering places by tags:\", selectedTagIds)\n\n    // Filter places by selected tags (or show all if none selected)\n    mapsController.placesManager.filterByTags(\n      selectedTagIds.length > 0 ? selectedTagIds : null,\n    )\n  }","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/javascript/controllers/places_filter_controller.js#L1-L30","documentation":"The places filter controller reads a global window.mapsController and warns when it (or its placesManager) is missing. Critically, nothing in this codebase ever assigns window.mapsController — the Maps V2 controller is a Stimulus controller and is never exposed on window — so this guard fails by design and tag-based place filtering never runs. It is a stale global-variable contract left over from an older map implementation.","triggerScenarios":"Any interaction that invokes filterPlaces (changing a place-tag checkbox) on a page where the filter controller is connected: window.mapsController is undefined in every case because no code sets it, so the warning fires and filtering is a no-op.","commonSituations":"After migrating from a legacy map that exported a window global to the Maps V2 Stimulus architecture; new tag-filter UI wired to this controller; devs assuming the map controller self-registers globally as in older versions.","solutions":["Replace the window global with a Stimulus lookup, mirroring the realtime controller: this.application.getControllerForElementAndIdentifier(mapElement, \"maps--maplibre\") where mapElement is the map container (query '[data-controller~=\"maps--maplibre\"]').","Alternatively have maplibre_controller expose itself via a custom event or a dispatched callback that the filter controller listens for, removing the global entirely.","If a quick shim is needed, assign window.mapsController = this inside maplibre_controller.connect() — but prefer the Stimulus lookup."],"exampleFix":"// before\nconst mapsController = window.mapsController\nif (!mapsController || !mapsController.placesManager) {\n  console.warn(\"Maps controller or placesManager not found\")\n  return\n}\n\n// after\nconst mapElement = document.querySelector('[data-controller~=\"maps--maplibre\"]')\nconst mapsController =\n  mapElement &&\n  this.application.getControllerForElementAndIdentifier(mapElement, \"maps--maplibre\")\nif (!mapsController || !mapsController.placesManager) {\n  console.warn(\"Maps controller or placesManager not found\")\n  return\n}","handlingStrategy":"validation","validationCode":"const el = document.querySelector('[data-controller~=\"maps--maplibre\"]')\nconst ctrl =\n  el && this.application.getControllerForElementAndIdentifier(el, \"maps--maplibre\")\nif (!ctrl?.placesManager) return","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rely on window globals for Stimulus controllers; use application.getControllerForElementAndIdentifier or outlets.","Consider Stimulus Outlets (maps--maplibre-outlet) so the framework resolves the dependency and fails visibly at connect time.","Grep for window.<name> reads that have no matching assignment when refactoring away from legacy globals."],"tags":["stimulus","window-global","undefined-variable","legacy-migration","places"],"backgroundTag":"undefined-global-variable","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}