Skip to content

Commit eb0b3cc

Browse files
felixtrzmeta-codesync[bot]
authored andcommitted
fix(scene-understanding): remove duplicate WebXR type declarations and add runtime checks
Summary: - Removed duplicate `declare global` block for WebXR Anchors API (types already exist in `types/webxr`) - Added runtime check for `session.restorePersistentAnchor` before invocation (handles browsers without persistent anchors support) - Added runtime check for `anchor.requestPersistentHandle` before invocation (handles optional WebXR feature) - Fixes TypeScript errors: duplicate identifier conflicts and unsafe property access Reviewed By: zjm-meta Differential Revision: D87710473 Privacy Context Container: L1334777 fbshipit-source-id: 5fc733471c620c61d9e4a5f37e4f221597f0bd52
1 parent e672845 commit eb0b3cc

1 file changed

Lines changed: 14 additions & 46 deletions

File tree

packages/core/src/scene-understanding/scene-understanding-system.ts

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
/**
9-
* Type declarations for WebXR Anchors API persistence features.
10-
*
11-
* These extensions to the WebXR Device API allow anchors to persist across sessions,
12-
* enabling virtual objects to maintain their real-world positions even after the
13-
* application is closed and reopened.
14-
*
15-
* @see {@link https://github.com/immersive-web/anchors/blob/main/explainer.md WebXR Anchors Module}
16-
*/
17-
declare global {
18-
interface XRAnchor {
19-
/**
20-
* Requests a persistent handle (UUID) for this anchor.
21-
* The UUID can be used with restorePersistentAnchor() to restore the anchor in future sessions.
22-
*/
23-
requestPersistentHandle(): Promise<string>;
24-
/**
25-
* Deletes this anchor, removing it from tracking.
26-
*/
27-
delete(): void;
28-
}
29-
30-
interface XRSession {
31-
/**
32-
* Array of UUIDs for all persistent anchors available in this session.
33-
*/
34-
readonly persistentAnchors: readonly string[];
35-
/**
36-
* Restores a previously created persistent anchor using its UUID.
37-
* @param uuid - The persistent handle returned from requestPersistentHandle()
38-
* @returns The restored anchor, or rejects if the anchor cannot be found
39-
*/
40-
restorePersistentAnchor(uuid: string): Promise<XRAnchor>;
41-
/**
42-
* Permanently deletes a persistent anchor.
43-
* @param uuid - The persistent handle of the anchor to delete
44-
*/
45-
deletePersistentAnchor(uuid: string): Promise<void>;
46-
}
47-
}
48-
498
import { createSystem, Entity, Types } from '../ecs/index.js';
509
import {
5110
BoxGeometry,
@@ -471,6 +430,13 @@ export class SceneUnderstandingSystem extends createSystem(
471430

472431
// Attempt to restore the anchor using the saved UUID
473432
this.anchorRequested = true;
433+
434+
if (!session.restorePersistentAnchor) {
435+
console.warn('XRSession.restorePersistentAnchor not supported');
436+
this.anchorRequested = false;
437+
return;
438+
}
439+
474440
this.xrAnchor = await session.restorePersistentAnchor(savedUuid);
475441

476442
if (!this.xrAnchor) {
@@ -513,11 +479,13 @@ export class SceneUnderstandingSystem extends createSystem(
513479

514480
// Request a persistent handle for the anchor so it can be restored in future sessions
515481
try {
516-
const uuid = await this.xrAnchor.requestPersistentHandle();
517-
localStorage.setItem(
518-
SceneUnderstandingSystem.ANCHOR_UUID_STORAGE_KEY,
519-
uuid,
520-
);
482+
if (this.xrAnchor.requestPersistentHandle) {
483+
const uuid = await this.xrAnchor.requestPersistentHandle();
484+
localStorage.setItem(
485+
SceneUnderstandingSystem.ANCHOR_UUID_STORAGE_KEY,
486+
uuid,
487+
);
488+
}
521489
} catch (_error) {
522490
// Persistence not supported or failed - anchor will work for this session only
523491
}

0 commit comments

Comments
 (0)