Comments (10)
The SSR build fail is due to Clover's inclusion of OpenSeadragon as a dependency. OpenSeadragon includes function calls on instantiation to the browser window -- which causes the crash.
To accommodate this, Clover must be imported in an alternative method. I'm not extremely familiar with Gatsby these days, however, in Next.js this is completed using the next/dynamic
(https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#importing-client-components). See https://samvera-labs.github.io/clover-iiif/docs/viewer#nextjs.
In Gatsby, this could possibly be completed with the following pattern:
import React, { Suspense, lazy, useEffect, useState } from "react";
const CloverViewer = lazy(() =>
import("@samvera/clover-iiif").then((Clover) => Clover.Viewer)
);
const DynamicCloverViewer = () => {
const [isClient, setIsClient] = useState(false);
useEffect(() => {
// This effect will run only once after the initial render, hence setting isClient to true
setIsClient(true);
}, []);
return (
<div>
{isClient && (
<Suspense fallback={<div>Loading...</div>}>
<CloverViewer iiifContent="https://api.dc.library.northwestern.edu/api/v2/works/76d0aebe-fc8a-4c6f-91dd-31026e67301e?as=iiif" />
</Suspense>
)}
</div>
);
};
export default DynamicCloverViewer;
from clover-iiif.
@MWhiteFearless Here's a codesandbox as an example if helpful.
https://codesandbox.io/p/sandbox/clover-lazy-suspense-8vgwg4
Let me know if this works for you in Gatsby!
from clover-iiif.
Thanks for the suggestion! Unfortunately I still get the same build errors with those changes
from clover-iiif.
Thanks for the suggestion! Unfortunately I still get the same build errors with those changes
Hmmm... Darn. Do you have a public repo of your codebase?
from clover-iiif.
Unfortunately our project is private, though we have been able to deploy Mirador successfully in the project (which also uses openseadragon) so I wonder if the issue might be something else? Mirador doesn't actually work for our use case which is why I'm still trying to get Clover to deploy :)
from clover-iiif.
@MWhiteFearless If you are restricting yourself to just the Viewer component, can you try this revised component where the Viewer is the default export? I'm able to get this to build in this Gatsby instance.
https://codesandbox.io/p/devbox/gatsby-clover-98c3lw?file=%252Fsrc%252Fcomponents%252Fviewer.js
Note the difference on the lazy import
const CloverViewer = lazy(() => import("@samvera/clover-iiif"))
Full block:
import React, { Suspense, lazy, useEffect, useState } from "react"
const CloverViewer = lazy(() => import("@samvera/clover-iiif"))
const DynamicCloverViewer = () => {
const [isClient, setIsClient] = useState(false)
useEffect(() => {
// This effect will run only once after the initial render, hence setting isClient to true
setIsClient(true)
}, [])
return (
<div>
{isClient && (
<Suspense fallback={<div>Loading...</div>}>
<CloverViewer iiifContent="https://api.dc.library.northwestern.edu/api/v2/works/76d0aebe-fc8a-4c6f-91dd-31026e67301e?as=iiif" />
</Suspense>
)}
</div>
)
}
export default DynamicCloverViewer
from clover-iiif.
@MWhiteFearless I grossly overlooked your React version. Sadly, Clover has issues with older versions of React. Is it possible to update React 18 @latest
for your project? This in conjunction with my previous comment might send it in the right direction.
from clover-iiif.
I tried the react 18 and lazy/Suspense suggestions together and still get the same error, next maybe I'll try this workaround https://www.gatsbyjs.com/docs/using-client-side-only-packages/#workaround-4-load-client-side-dependent-components-with-loadable-components. Interesting that you can get it to build without issue, maybe this is an issue related to Gatsby 3
from clover-iiif.
I determined that the errors I was running in to were actually related to @iiif/vault and incompatible dependency versions there, not openseadragon. I've moved forward with implementing openseadragon on its own and have it working :) thanks for helping troubleshoot! The lazy loading suggestion was helpful for getting openseadragon working. I think to get clover working on my project we would have to upgrade gatsby and node, which unfortunately isn't an option for us. We can probably close this issue!
from clover-iiif.
@MWhiteFearless I'm going to close this but I also want to make you aware of a new Image component that is essentially a styled OpenSeadragon wrapper. https://samvera-labs.github.io/clover-iiif/docs/image
from clover-iiif.
Related Issues (20)
- No thumbnail display on multicanvased work if the canvas is missing a label
- With one video in an iFrame, Clover's canvas doesn't fill the container.
- Control buttons not shown when on full-screen
- Add next/previous Media controls to the ImageViewer
- Configuration Improvements
- Build error: 'Document' is not exported from 'flexsearch' HOT 3
- HLS should render if the mime-type is an application/vnd.apple.mpegurl, not just if the file ends with .m3u8
- Add support for Ranges to build a table of contents HOT 1
- Clover doesn't always toggle between canvases on thumbnail click
- Tiled image not loading correctly
- Audio visualizer appears under accompanyingCanvas
- Audio visualizer disappear on page change
- Download link opens a vault:// address instead of referenced resource.
- Previous tab and next tab components mounted when switching tabs
- Clover viewer overtakes body on smaller viewports in some cases
- Annotation tab/overlays should not be on by default HOT 1
- CanvasHeight set to 100% seems to collapse clover-viewer-content when below 767px window width
- Zoom view does not display HOT 1
- Collection of InformationPanel issues
- Support contentState motivations for Annotations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clover-iiif.