Migrating from v1.0 to v1.1¶
v1.1 is fully backward compatible. Your existing code continues to work unchanged. This guide covers adopting the new create() API.
What Changed¶
| v1.0 | v1.1 | |
|---|---|---|
| Initialization | window.__XRGALLERY_CONFIG__ global | XRGallery.create() function |
| Element targeting | Hardcoded #renderCanvas | Any CSS selector or DOM element |
| Cloud tours | Not supported via npm package | sceneId parameter fetches from cloud |
| Lifecycle | No cleanup API | viewer.dispose() / viewer.isDisposed() |
| Framework support | Manual canvas setup | Works with React refs, Vue refs, etc. |
| TypeScript | Basic types | Full type tree for all config objects |
Before / After¶
Self-Hosted Tour¶
Cloud Tour (New in v1.1)¶
<div id="app"></div>
<script src="viewer-bundle.iife.js"></script>
<script>
(async () => {
const viewer = await XRGallery.create({
element: '#app',
sceneId: 'YOUR_SCENE_ID'
});
})();
</script>
This was not possible in v1.0 without manually setting up Firebase config.
React Component¶
function VRViewer({ sceneId }: { sceneId: string }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const v = XRGallery.create({ element: ref.current, sceneId });
return () => { v.then(v => v.dispose()); };
}, [sceneId]);
return <div ref={ref} style={{ width: '100%', height: '100%' }} />;
}
Step-by-Step Migration¶
1. Update the Package¶
2. Replace the Global Config¶
Remove window.__XRGALLERY_CONFIG__ and use create() instead.
Find:
Replace with:
const viewer = await XRGallery.create({
element: '#app', // or your container
config: { ... } // same config object
});
3. Add a Container Element¶
The v1.0 approach required a <canvas id="renderCanvas"> in your HTML. With create(), you just need a container <div>:
<!-- v1.0: needed this in your HTML -->
<canvas id="renderCanvas"></canvas>
<!-- v1.1: just a container div, canvas is created automatically -->
<div id="app" style="width: 100%; height: 100vh;"></div>
4. Add Cleanup (Optional but Recommended)¶
// Store the viewer instance
const viewer = await XRGallery.create({ ... });
// Clean up when done (SPA navigation, component unmount, etc.)
viewer.dispose();
No Breaking Changes¶
Everything from v1.0 still works:
window.__XRGALLERY_CONFIG__auto-initializationwindow.__XRGALLERY_OPTIONS__(viewer.html)XRGallery.init()low-level API- All config options and hotspot types
- Canvas lookup by
#renderCanvas
You can migrate incrementally.