Skip to content

Add store.onSessionEnd for reliably detecting session end - #504

Open
kvvasuu wants to merge 1 commit into
pmndrs:mainfrom
kvvasuu:feat/xr-store-on-session-end
Open

Add store.onSessionEnd for reliably detecting session end#504
kvvasuu wants to merge 1 commit into
pmndrs:mainfrom
kvvasuu:feat/xr-store-on-session-end

Conversation

@kvvasuu

@kvvasuu kvvasuu commented Aug 26, 2026

Copy link
Copy Markdown

Problem

There's no documented, supported way to react to an XR session ending.
session.addEventListener('end', ...) looks like the obvious approach, but it's easy to end up attached to a stale/incorrect session reference across re-renders, since consumers typically get session reactively (e.g. useXR(state => state.session)).
Internally, <XR> already solves this correctly by diffing state.session in a store.subscribe callback - but that pattern wasn't exposed or documented anywhere.

Change

  • Add store.onSessionEnd(callback): a thin wrapper around store.subscribe that fires when the session transitions from non-null to null, and returns an unsubscribe function. Mirrors the existing destroy() doc comment ("for exiting XR use store.getState().session?.end()") with a symmetric, documented way to detect the end.
  • Document the new function in the store docs table.

Testing

  • pnpm -r check:prettier
  • pnpm -r check:eslint
  • pnpm -r build

session.addEventListener('end', ...) is easy to attach to a stale session
reference across re-renders. XRStore already tracks this internally via
its own 'end' listener, so expose it as a store subscription helper
instead of making every consumer reimplement prev/current session diffing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant