Skip to content

feat(widget): keep state when a host replaces the element #349

Description

@Ardnived

Summary

On a Wix router page, Back/Forward to a URL the widget pushed makes Wix re-render the page and replace <sahaj-atlas> with a new element. The new element boots at the right route, but releaseOwnership() clears the query cache when a different element takes over, so every such press costs ~1.6 s, a full refetch and a new billed Mapbox map load. Keep the widget's state across a same-key replacement, and point hosts at SahajCloud's new Install tab.

Goal context

Part of #348 — the widget side: the map no longer reloads on Back/Forward on Wix, and the docs send volunteers to the setup screen.

Approach

  • src/Widget.tsx:503 — in connectedCallback, when pendingTeardown is set and a different element arrives inside TEARDOWN_GRACE_MS (:476), it calls releaseOwnership() (:481), which clears queryClient and the API key. When the API key is unchanged (the loader did not run again; embed.config is the same), transfer ownership instead: cancel the teardown, keep the query cache, owner = this. A different key keeps today's release — the reason that guard exists stands.
  • Keep the Mapbox map instance across the swap if the map's container can move into the new shadow root; otherwise accept a fresh map, with the data cache kept.
  • docs/embedding.md: a line at the top sending site owners to the Install tab in SahajCloud, and a Wix section — Custom Element only (tag sahaj-atlas, Server URL auto.js?key=…), never Embed HTML; SEO needs the Velo router the Install tab generates.
  • CHANGELOG.md: the replacement behaviour, and the docs change.

Interfaces

  • Consumes from sydevs/SahajCloud: the Install tab, which embedding.md links to. No API change.

Acceptance criteria

  • Replacing <sahaj-atlas> with a new element, same key, inside the grace window makes no new SahajCloud read and keeps the current route.
  • A replacement with a different key still releases and re-authenticates, as today.
  • embedding.md opens with the pointer to the Install tab and has a Wix section.

Verification checklist

  • pnpm test:run for the new jsdom spec covering same-key and different-key replacement.
  • On https://sydevelopers.wixsite.com/atlas-spike-classic/about, inject the PR's preview auto.js, wait for data-sahaj-atlas-ready, then old.replaceWith(document.createElement('sahaj-atlas')): no request to cloud.sydevelopers.com/api/* follows, and content reappears.
  • .claude/skills/pr-prep/check.sh passes.

Notes

Blocked by: sydevs/SahajCloud#1055 — the embedding.md pointer names the Install tab, which ships there; the widget change itself can be built alongside.

Measured with a simulated swap, not a real Custom Element (that needs a Premium site); confirmed at sahajayoga.ca's go-live.

Activity

  1. added theissue type on Oct 31, 2026
  2. moved this from Awaiting to Blocked in SYDevelopers Technical Roadmapon Oct 31, 2026
  3. sydevs-bot commented on Nov 10, 2026

    @sydevs-bot
    Contributor

    #1055 closed, so nothing blocks this now. Say @sydevs-bot implement to start it, or @sydevs-bot revise to rework it first.

    🤖 sydevs dispatcher

  4. moved this from Blocked to Awaiting in SYDevelopers Technical Roadmapon Nov 10, 2026
  5. Ardnived commented on Nov 10, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot implement

  6. added
    bot:working
    on Nov 10, 2026
  7. sydevs-bot commented on Nov 10, 2026

    @sydevs-bot
    Contributor

    🤖 no session running
    approved by Ardnived

    recent dispatches
    • 17:58Z implement · attempt 1 · session · done
    • 17:58Z implement · attempt 1 · session

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

  8. moved this from Awaiting to Working in SYDevelopers Technical Roadmapon Nov 10, 2026
  9. removed
    bot:working
    on Nov 10, 2026
  10. Ardnived commented on Nov 11, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot implement

  11. sydevs-bot commented on Nov 11, 2026

    @sydevs-bot
    Contributor

    #383 is already open for this ticket, so I will not start a second implementation.

    🤖 sydevs dispatcher

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

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions