Skip to content

fix(map): say why Find my location did nothing when it is blocked #321

Closed

Description

@antontcymbal

Summary

When the browser refuses the map's location request, tapping "Find my location" does nothing visible: no message and no next step, so it looks broken. Say what happened, in a dialog over the map.

Approach

1. A dialog on onError, not an inline alert

<GeolocateControl followUserLocation={false} onGeolocate={geolocateToSearch} /> has no onError (src/components/organisms/Mapbox/Map.tsx:524).

  • Hold the failure in Map.tsx local state: const [locationFailed, setLocationFailed] = useState(false), set from onError={() => setLocationFailed(true)}. A useState setter has a stable identity, so this handler needs none of the live-ref machinery useGeolocateToSearch carries.
  • Render the dialog as a sibling of <ReactMapGL>, in a fragment, rather than a child — nothing about it belongs to the map's own subtree.
  • Use the Modal atom (src/components/atoms/Modal/Modal.tsx): Modal + ModalContent + ModalFooter with a ModalClose-wrapped Button. The footer button gives touch a target bigger than the header ×. ModalContent portals through overlayContainer(), so it inherits the theme root and the brand variables, and sits at z-50 above the drawer stack. Radix owns Esc, the focus trap, and focus return to the locate control.
  • Copy: title={t('common.map.location_not_available')} and closeLabel={t('common.chrome.close')} already exist. description is common.map.location_failed, shipped by feat(translations): add the geolocate-failure message to sy-atlas-translations SahajCloud#1031: We couldn’t get your location. Search for a place instead. — a curly apostrophe, as seeded. That merge also widened location_not_available's own description to name this dialog's heading as its second role, so reuse that key for the heading rather than adding one.
  • The sentence must be live in production before this build can finish. feat(translations): add the geolocate-failure message to sy-atlas-translations SahajCloud#1031 declared and seeded the key, but production's global still answers common.map with find_my_location and location_not_available only (read 2026-10-26 23:55Z). A manager adds it — see ## Decisions. Until it is there, pnpm sync:translations --write writes a snapshot without the key and src/config/translations.test.ts fails on the new call site.
  • Do not put the place search inside the dialog. Map.tsx cannot import src/views/shared.tsx, which is where SearchField lives: shared.tsx imports MapSearch from the organisms barrel, which re-exports Mapbox, so that is a real cycle (src/hooks/use-geolocate.ts records it). The dialog says what happened and points at the search; the field stays in the header it already sits in.

What onError reaches, and the one case it cannot

Read off node_modules/mapbox-gl/dist/mapbox-gl-dev.js ([email protected]), not inferred:

  • GeolocateControl.onAdd calls _checkGeolocationSupport, which queries navigator.permissions.query({ name: 'geolocation' }) and hands _setupUI supported: false when the state is already denied. _setupUI then renders the button disabled with the GeolocateControl.LocationNotAvailable title. A disabled button fires no click, so trigger() never runs and no error event is ever emitted. So a permission blocked before the map loaded — the ordinary Chrome and Firefox case — cannot be caught by onError at all. The only signal there is the disabled control plus a title, which is invisible on touch.
  • onError does fire for: declining the browser prompt, a position that is unavailable, the 6-second positionOptions.timeout (and _startRequestTimeout's own code-3 fallback), and a pre-blocked permission in Safari, whose permissions.query rejects for geolocation so mapbox leaves the button enabled.
  • trackUserLocation is false here — we pass only followUserLocation={false}, and the default is false — so _onError's disable-and-relabel branch does not run. The button stays live after a refusal, and a second tap re-prompts.
  • The event payload is a plain object, { code, message, PERMISSION_DENIED, POSITION_UNAVAILABLE, TIMEOUT }, not a GeolocationPositionError. One dialog for every code is enough; do not branch on code.

Making the pre-blocked, disabled control speak would mean replacing Mapbox's own control. That is out of proportion to this bug and is not in this ticket.

2. Correct the handler-binding note the fix sits next to

docs/rules/mapbox.md ("Localizing Mapbox's own control strings") says Mapbox reads onGeolocate once at construction, and concludes "treat anything handed to a Mapbox control as bound once". The conclusion is safe; the mechanism is wrong. node_modules/react-map-gl/dist/esm/components/geolocate-control.js assigns thisRef.current.props = props on every render, and every listener it registers reads the handler off that ref — so a control's handlers are live. What made useGeolocateToSearch stale was its own useCallback(…, []).

Leave the hook's code alone: the [] deps and the live ref are still correct. Fix the explanation in both places — that paragraph in docs/rules/mapbox.md and the matching docblock in src/hooks/use-geolocate.ts — so a later author does not reason from the wrong mechanism. The locale prop on <ReactMapGL> genuinely is construction-only; that half of the note stands.

3. Give sync:translations the select the client gate now requires

pnpm sync:translations is the only sanctioned way the new key reaches src/config/translations.en.json, and it fails against production today, for every key — so it is this ticket's to fix.

scripts/sync-translations.mjs:105 builds ${PRODUCTION}/api/globals/sy-atlas-translations?locale=en&depth=0 with no select. SahajCloud rejects any API-client read that sends none (src/plugins/usage/hooks.ts:285, 400, The "select" query parameter is required for API clients). Measured against production on 2026-10-26 with a clients key: that URL answers 400; the same URL plus select[<tab>]=true for each of the script's own ten WIDGET_TABS (scripts/sync-translations.mjs:60) answers 200 and carries the whole widget bundle. The runtime path was never affected — src/config/api/fetch.ts:736 declares TRANSLATION_SELECT and sends it at :817. The node script is the one reader with no select.

  • Append one select[<tab>]=true per WIDGET_TABS entry. Add no new list: src/config/translations.test.ts:170 already pins that array against WIDGET_TRANSLATION_TABS, and a second spelling of the tabs would escape it. That test reads the array with arrayLiterals(script, 'const WIDGET_TABS[^=]*='), so WIDGET_TABS must stay a plain array literal — build the query string from it.
  • The 200 body carries id and event.title, which DROP and the explicit delete bundle.event.title already remove, so the stripping stage needs no change. emails is simply never selected now; leave it in DROP.
  • scripts/sync-translations.mjs:109 throws GET … answered 400. Is the key a production client key? — a wrong diagnosis for this failure, and the reason it reads as a credential problem. Include the response body in that message.

Acceptance criteria

  • Declining the browser's location prompt opens a dialog naming what happened, with no perceptible delay.
  • A location request that times out, or returns no position, opens the same dialog.
  • Esc and the dialog's own Close both dismiss it, and focus returns to the locate control.
  • The dialog renders inside the widget's theme root, not on the host page's document.body.
  • docs/rules/mapbox.md and src/hooks/use-geolocate.ts no longer say a Mapbox control's handlers are construction-bound, and both name the hook's own useCallback(…, []) as what made the handler stale.
  • pnpm sync:translations reaches production and reports drift instead of throwing on a 400.
  • The script still spells the widget tabs exactly once, and src/config/translations.test.ts passes unchanged.
  • pnpm test:run passes, src/config/translations.test.ts included, with the new key wired to its one call site.

Verification checklist

  • First, confirm production carries the copy. It did not at 2026-10-26 23:55Z, and nothing below can pass until it does. With ATLAS_API_KEY set to a production client key:
    bash curl -gs 'https://cloud.sydevelopers.com/api/globals/sy-atlas-translations?locale=en&depth=0&select[common]=true' \ -H "Authorization: clients API-Key $ATLAS_API_KEY" | grep location_failed
    No match means the manager edit in ## Decisions has not happened yet. Stop and say so.
  • pnpm sync:translations (no --write), with the same key: it answers with a drift report, not answered 400. Watch it fail on the current script first, so the fix is proven rather than assumed.
  • pnpm sync:translations --write, then confirm src/config/translations.en.json gained common.map.location_failed, then pnpm test:run src/config/translations.test.ts. The snapshot is generated, never hand-edited.
  • .claude/skills/pr-prep/check.sh.
  • Browser, attended, through the Playwright MCP — this repo has no Playwright lane (pnpm test:smoke is fetch-only). Serve pnpm dev with clients/me stubbed, per docs/rules/mapbox.md → "Checking map behavior in a browser", and install this before the page loads:
    js await page.addInitScript(() => { Object.defineProperty(navigator, 'permissions', { value: { query: async () => ({ state: 'prompt', onchange: null }) }, }) Geolocation.prototype.getCurrentPosition = (_ok, fail) => fail({ code: 1, message: 'User denied Geolocation', PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3, }) })
    Then click button.mapboxgl-ctrl-geolocate and screenshot: the dialog shows the new sentence. Re-run with code: 3 for the timeout path. The state: 'prompt' half matters — it is what keeps the control enabled.
  • Same page with the stub answering state: 'denied': the control renders disabled and no dialog appears. This is the out-of-scope path above — observe the limit rather than assume it.

Open questions

Decisions

  • How does common.map.location_failed reach production's copy? → A — a manager adds the sentence at /admin/globals/sy-atlas-translations (Ardnived, 2026-10-26). Paste the seeded English exactly: We couldn’t get your location. Search for a place instead. Rejected: pnpm seed translations against production, which rewrites every seeded group wholesale and would replace copy a manager has since reworded. Done 2026-10-28 (chore(translations): enter the production English copy for event.display.room SahajCloud#1025); a clients read at 05:28Z answers with the sentence.

Notes

Found in a whole-Atlas UX audit (2026-10-25).

The reviewer asked for a dialog over the earlier inline-alert-plus-focus-move plan (2026-10-25). That also retires the old "focus moves to the place search" criterion: a Radix dialog traps focus in itself and hands it back to the control on close.

The select fix joins this ticket because it is what lets this ticket's own verification run: one reviewer, one sitting. ⚠ #316 part 4 specifies the same fix, and #316 is in flight — whichever lands first, the other rebases onto it.

The stored location_failed value carries two trailing newlines, from the paste. Harmless on screen, and the snapshot copies production faithfully, so fixing it is a SahajCloud admin edit rather than anything here.

@sydevs-bot implement starts the work, once the sentence is live in production's sy-atlas-translations.

Activity

  1. added theissue type on Oct 25, 2026
  2. moved this from Revising to Proposed in SYDevelopers Technical Roadmapon Oct 25, 2026
  3. Ardnived commented on Oct 25, 2026

    @Ardnived
    Contributor

    @sydevs-bot revise this to use an alert or modal or whatever the simplest solution is, instead of it being inline.

  4. moved this from Proposed to Revising in SYDevelopers Technical Roadmapon Oct 25, 2026
  5. added
    bot:working
    on Oct 25, 2026
  6. sydevs-bot commented on Oct 25, 2026

    @sydevs-bot
    Contributor

    🤖 no session running

    recent dispatches
    • 05:26Z implement · attempt 1 · session · done
    • 05:26Z implement · attempt 1 · session
    • 00:38Z implement · attempt 1 · session · done
    • 00:38Z implement · attempt 1 · session
    • 23:51Z revise · attempt 1 · session · done

    Written by the sydevs dispatcher. Sessions never edit this comment.

  7. sydevs-bot commented on Oct 25, 2026

    @sydevs-bot
    Contributor

    Rewritten for a dialog: onError opens a Modal from Map.tsx local state. Radix traps focus and hands it back to the control, so the old "focus moves to the search field" criterion is gone.

    Two things the code forced:

    • onError cannot catch the headline case. mapbox-gl queries navigator.permissions at onAdd and renders the button disabled when the state is already denied, so Chrome and Firefox emit no event for a permission blocked before load. The dialog covers the prompt refusal, a timeout, an unavailable position, and Safari's pre-blocked case. Replacing Mapbox's control is out of proportion, so that path is out of scope.
    • The copy blocks it. Filed feat(translations): add the geolocate-failure message to sy-atlas-translations SahajCloud#1031 for common.map.location_failed, plus the Blocked by: line. Title and close label reuse keys that exist.

    Joined in: docs/rules/mapbox.md says a Mapbox control's handlers bind once at construction. react-map-gl refreshes them every render — the stale handler was the hook's own useCallback(…, []).

    @sydevs-bot implement starts the work once #1031 ships.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  8. removed
    bot:working
    on Oct 25, 2026
  9. 20 remaining items

  10. sydevs-bot commented on Oct 27, 2026

    @sydevs-bot
    Contributor

    Not started: production still does not carry the sentence.

    A clients read of production's sy-atlas-translations at 00:40Z answers common.map with find_my_location and location_not_available only. common.map.location_failed is absent.

    curl -gs 'https://cloud.sydevelopers.com/api/globals/sy-atlas-translations?locale=en&depth=0&select[common]=true'
    

    Decision 1A asks a manager to add it at /admin/globals/sy-atlas-translations, pasting exactly:

    We couldn’t get your location. Search for a place instead.

    I built nothing. The ticket is one PR, and pnpm sync:translations --write would write a snapshot without the key, so src/config/translations.test.ts fails on the dialog's new call site. The docs correction and the select fix ride the same PR, so neither ships ahead of it.

    Say @sydevs-bot implement again once the sentence is live.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  11. removed
    bot:working
    on Oct 27, 2026
  12. moved this from Approved to Revising in SYDevelopers Technical Roadmapon Oct 27, 2026
  13. Ardnived commented on Oct 28, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement — common.map.location_failed is now in production's sy-atlas-translations global (added and published 2026-10-28, sydevs/SahajCloud#1025).

  14. added
    bot:working
    on Oct 28, 2026
  15. moved this from Awaiting to Working in SYDevelopers Technical Roadmapon Oct 28, 2026
  16. sydevs-bot commented on Oct 28, 2026

    @sydevs-bot
    Contributor

    Built, not shipped: one assertion is red on two keys this ticket cannot reference.

    Branch claude/fix-321-location-blocked, four commits, no PR. The dialog, the docs correction and the select fix are all done, and the lean gate is green but for one case.

    The copy blocker cleared: location_failed is live, read 05:28Z. That same publish also brought event.display.room (#316, in flight) and registration.form.subscribe (#147, unbuilt). The snapshot is generated wholesale, so both land in it, and translations.test.ts:229 reddens on any snapshot key the source references nowhere.

    Question 1 in the body asks how they clear. Recommended: a manager removes subscribe from the production global until #147 wires it — that unblocks #316 too.

    Still owed: the attended browser pass. This container has no VITE_MAPBOX_ACCESSTOKEN, so no map can be constructed to click.

    Answer with @sydevs-bot revise 1A, then implement again.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  17. removed
    bot:working
    on Oct 28, 2026
  18. moved this from Working to Awaiting in SYDevelopers Technical Roadmapon Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions