Skip to content

Upgrade to clover v4.x - #517

Merged
kdid merged 2 commits into
deploy/stagingfrom
preview/clover-4
Nov 11, 2026
Merged

kdid merged 2 commits into
deploy/stagingfrom
preview/clover-4

Conversation

@kdid

@kdid kdid commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Upgrades Digital Collections from the deprecated @samvera/clover-iiif 3.17.0 to @nulib/clover 4.4.2 (now maintained in nulib-ds/clover) for the work-page viewer, the IIIF primitives (title, summary, metadata, thumbnails) and the collection/related-item sliders.

Clover 4 is a rewrite, not a drop-in upgrade: settings are props instead of an options object, the markup and class names are new, and the package is ESM-only. This PR moves DC onto it while keeping the current look and behavior. Users get Clover 4's viewer, with highlighted content-search hits, a transcript view for A/V, and new image controls, while panel tabs, sliders and typography still look like current DC.

User-facing:

  • Viewer: the panel shows Search and Annotations, plus About during a content search, as now. It opens automatically for works with annotations. On audio/video works, the VTT tab is labeled "Chapters".
  • Sliders: same look as now (purple title, pill "View All" button, same column counts per breakpoint). Thumbnails are now consistently square, which also fixes the mixed-size thumbnails currently visible on some prod pages.
  • Transcripts/VTT: load correctly (see the request change below).

Changes

  • Dependency: replaced @samvera/clover-iiif with @nulib/clover 4.4.2. pages/_app.tsx now imports @nulib/clover/styles.css.
  • Viewer (components/Clover/ViewerWrapper.tsx, `components/Work/EmbeddedViewer.tsx):
    • Moved 3.x options to Clover 4 props: header, defaultPanelOpen, panelLayout="tabs", panelSections, panelLabels, request, searchQuery, onContentStateChange. The 640px canvas height is now --clover-body-height.
    • Removed the 3.x MutationObserver that forced the Search tab open. Clover 4 opens Search itself when searchQuery is set.
    • The viewer loads through components/Clover/CloverViewer.tsx, because next/dynamic's require.resolveWeak can't resolve an import-only package.
  • Requests (components/Clover/clover-request.ts, new): Clover 4 applies one request setting to everything it fetches.
    • Credentials still go with JSON requests (manifests, image info.json, search, annotation pages), so restricted works keep working.
    • Text resources (WebVTT under /public/vtt/) are fetched without cross-origin credentials, because that host answers Access-Control-Allow-Origin: *, which browsers reject for credentialed requests. Without this, the transcript tab was blank.
    • A credentialed request that's still rejected is retried once without credentials.
  • Primitives (TopInfo, Metadata, Hero, Homepage/Overview, EmbedResources):
    • Props renamed to Clover 4's value=. Metadata's custom search links moved from customValueContent to renderValue.
    • Hero builds the region-cropped IIIF image URL itself, since Clover 4's Thumbnail has no region prop.
  • Sliders (components/Clover/SliderWrapper.tsx):
    • Now <Items layout="slider">.
    • Keeps DC's credentialed collection fetch, abort handling and error-boundary behavior.
    • The "View all" search URL is passed as the collection's homepage.
    • Nested collections are filtered out, as the 3.x CSS used to hide them.
  • Styles (ViewerWrapper.module.css, SliderWrapper.module.css): rewrote the overrides for Clover 4's markup.
    • Panel text is rescaled to DC's gr3 size. Clover 4 sizes text in rem, and DC's root is 19px, so panel text came out too large.
    • Slider titles, the "View all" pill and the square thumbnails match current DC.
    • The column counts and gaps per breakpoint are unchanged.
  • Jest (jest.config.js): transform @nulib/clover and @iiif/parser, which are ESM-only. Slider and viewer tests were updated for Clover 4, and clover-request.test.ts was added.
  • Data fix (lib/constants/homepage.ts): one homepage overview thumbnail URL contained //full/ and returned 403. Clover 3 built a different URL from the image service and hid the typo.

Testing

https://preview-clover-4.dc.rdc-staging.library.northwestern.edu/

npm ci
export NEXT_PUBLIC_DCAPI_ENDPOINT=https://dcapi.rdc-staging.library.northwestern.edu/api/v2 &&  npm run dev 

Known differences / follow-ups

  • Deep links from content-search results open on the first hit instead of the page that was clicked, because Clover 4's Search panel auto-selects the first hit. A fix has been prepared for nulib-ds/clover Center searches around user and start from current canvas. nulib-ds/clover#397, h. Once it's released, bump @nulib/clover.
  • Search text isn't saved in the URL: typing in the viewer's Search no longer updates ?content-search=. Clover 4 has no contentSearchCallback; there's a TODO in ViewerWrapper.tsx. Searches started from the URL still work.
  • Homepage overview video thumbnail (HLS .m3u8) didn't play, because Clover 4's Thumbnail only renders <img>. The video tile is now a still poster frame.

@kdid kdid self-assigned this Nov 5, 2026
@kdid
kdid requested review from mathewjordan and a balanced review from Copilot November 5, 2026 21:18
@kdid
kdid requested review from bmquinn and removed request for Copilot November 5, 2026 21:19

@bmquinn bmquinn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad we're on the latest Clover, and the content search looks awesome now:
Image

@mathewjordan

Copy link
Copy Markdown
Member

This looks great. I would like to spend a bit of time combing through the site in detail. At first glance, the viewer is looking nice but the slider in Related Items could use some touchups.

Thanks for pushing through. Also we are now at 4.5.6!!!

@kdid kdid changed the title Upgrade to clover v4.4.2 Upgrade to clover v4.x Nov 6, 2026
@mathewjordan

Copy link
Copy Markdown
Member

Slider notes (Explore Further / related-items sliders)

1. Prev/next buttons sit ~24px too high. Clover positions them off a variable this branch doesn't update:

:is(button.clover-items-scroll-prev, button.clover-items-scroll-next) {
  position: absolute;
  top: calc(var(--clover-items-picture-height) / 2);
  translate: 0 -50%;
}
.clover-items { --clover-items-picture-height: var(--clover-items-height, 8rem); }

Clover's slider sizes pictures by height (.clover-items-picture img { width: auto; height: var(--clover-items-picture-height) }), but SliderWrapper.module.css sizes cards by width and squares them with aspect-ratio: 1, leaving --clover-items-picture-height at the stale 8rem default. Measured on "More Like This" at a 1082px frame: button center 1140.6px vs picture center 1164.5px.

They should be vertically centered on the card image (not the card including its caption). Setting --clover-items-picture-height on .clover-items to the same computed card size fixes the centering and lines up the frame's edge-shade gradients, which read the same variable. It needs to resolve as a length rather than a percentage, so container query units on the frame:

.styledSliderIIIFWrapper :global(.clover-items-frame) { container-type: inline-size; }
.styledSliderIIIFWrapper :global(.clover-items) {
  --clover-items-picture-height: calc(
    (100cqw - (var(--slider-columns) - 1) * var(--slider-gap)) / var(--slider-columns)
  );
}

2. Buttons should hang off the slider edge. Clover insets them (inset-inline-start/end: var(--clover-space-2xs)), so they overlap the first and last card. They should overhang the slider's outer edge while the page gutter has room — roughly half the control outside — and only tuck back inside once the container meets the viewport, at the breakpoint where Container's gutter goes away.

3. Style the clamped-label overlay like the "View as IIIF" popover. The full-text box that appears on hover/focus is .clover-items-label-full (rendered for .clover-items-label[data-clamped]). Clover ships it as a plain white block with a top-edge shadow, no radius and no inline padding. It should match .styledIIIFShareContent in components/Shared/IIIF/Share.module.css — white, border-radius: 3px, box-shadow: 5px 5px 19px 0 #0002, DC padding — so the two overlays on the work page read as one treatment.

Also: upgrade to Clover 4.9.2

4.9.2 is the current latest. Verified locally against this branch: tsc --noEmit clean, 81/81 Jest suites (320 tests) pass, and every .clover-* class name and --clover-* custom property these modules target is unchanged from 4.4.2.

@mathewjordan

Copy link
Copy Markdown
Member

Download and Share crashes on a video work

Opening Download and Share on an Audio/Video work throws RangeError: Invalid time value at lib/utils/time-helpers.ts:22 in convertTime, and the work page is replaced by the error boundary ("Something went wrong / Invalid time value").

Cause. ContentState.tsx still expects Clover 3's numeric PointSelector.t:

// components/Work/ActionsDialog/ContentState/ContentState.tsx:78-79
const targetSelector = contentState?.json?.target?.selector;
const selectorValue = targetSelector?.t || targetSelector?.value;

Clover 4 always writes a FragmentSelector instead (dist/core/content-state.mjs):

const fragment = time != null && time > 0 ? `t=${Math.round(time * 100) / 100}` : region ? `xywh=…` : null;
selector: { type: "FragmentSelector", value: fragment }

So targetSelector.t is undefined and selectorValue falls through to the string "t=12.34". It is truthy, so the label renders, and convertTime("t=12.34") does "t=12.34" * 1000 → NaN → new Date(NaN).toISOString() → RangeError. (Clover 4 still reads a PointSelector in core/content-state-reader.mjs, but it never emits one.)

Scope. A/V only: convertTime sits behind the ["Video", "Sound", "Audio"].includes(metadata?.activeCanvasResourceType) branch, and image works take the "Zoom to current view" branch, where the xywh= string is never parsed as a number.

Fix direction. Parse seconds out of the fragment rather than reading .t — note the media fragment may also be a range (t=start,end), so take the first number:

const seconds =
  targetSelector?.t ??
  Number(/(?:^|[?&#])?t=([\d.]+)/.exec(targetSelector?.value ?? "")?.[1]);

and guard convertTime with Number.isFinite(duration) so a malformed selector degrades instead of taking down the page.

@mathewjordan

Copy link
Copy Markdown
Member

Viewer thumbnail rail needs a max width for very wide items

On a work with a panoramic still — e.g. /items/513f420e-4ef6-4fa0-9174-2f5a6fcecca5, whose "tape 1 of 1 image" canvases are photographs of a videotape shot end-on — one thumbnail takes over the whole strip under the viewer and pushes the other views out of view.

Measured in the rail (.clover-template-default-rail → .clover-items[data-layout="slider"]), against a rail content width of ~873px:

item natural rendered
0 (video poster) 300×169 270×152
1 300×169 270×152
2 (tape still) 300×49 931×152

Cause. Clover's slider sizes thumbnails by height alone, with no cap:

.clover-items[data-layout=slider] .clover-items-picture img {
  width: auto;
  height: var(--clover-items-picture-height);
}

max-width computes to none and object-fit to fill, so a 6.1:1 still renders 6.1 × the strip height. DC's own related-items sliders don't show this because SliderWrapper.module.css already squares them (aspect-ratio: 1 + object-fit: cover); the viewer rail has no equivalent rule in ViewerWrapper.module.css.

Suggested fix — cap the width and crop rather than squash, alongside the existing --clover-body-height override:

.viewerWrapperStyled :global(.clover-items[data-layout="slider"]) .clover-items-picture img {
  max-width: calc(2 * var(--clover-items-picture-height));
  object-fit: cover;
}

Related, worth fixing in the same pass: --clover-items-picture-height resolves to Clover's default 8rem, which is 152px against DC's 19px root rather than the 128px Clover assumes — every rail thumbnail is 19% larger than intended. Setting it explicitly on .clover-items (where Clover declares it) would pin the strip height and give the max-width above a predictable basis.

@mathewjordan

Copy link
Copy Markdown
Member

…and a min width for narrow items in the viewer rail — squaring them handles both ends

Same root cause as the max-width note above (Clover's slider sizes thumbnails by height, width: auto), seen from the other direction. On /items/e34b2f42-07ac-40bc-9609-395346fa4f7f (Berkeley 1963, 5 views), measured in the rail against an 842px frame:

item label natural rendered caption
0 Front cover 166×300 84×152 39px (2 lines)
1 Participants 275×300 139×152 20px (1 line)
2 Festival schedule 300×233 196×152 20px
3 Ticket information 162×300 82×152 39px (2 lines)
4 Back cover 166×300 84×152 20px

Thumbnail widths span 82px to 196px in a single strip — a 2.4× spread — and the two narrowest squeeze their labels onto two lines while their neighbours stay on one, which is what makes the row look ragged. The strip isn't even full (~585px of items in an 842px frame), so the cramping buys nothing.

Rather than a separate min-width and max-width, one square box fixes both ends and gives every label an identical column to sit under:

.viewerWrapperStyled :global(.clover-items[data-layout="slider"]) .clover-items-picture {
  width: var(--clover-items-picture-height);
}
.viewerWrapperStyled :global(.clover-items[data-layout="slider"]) .clover-items-picture img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

contain rather than cover here: DC's own related-items sliders crop to square, but a tall brochure page cropped to a square loses most of the page, and Clover already paints .clover-items-picture with --clover-color-secondary-muted, so contain letterboxes onto that background and keeps the whole view legible. Worth deciding deliberately — cover is tidier, contain is more useful for paged documents.

Two things to check when implementing:

  • Size the picture, not the item: .clover-items-figure[data-parts] lays its pictures out through grid-template-columns: subgrid, so a multi-part canvas should still be able to render its parts side by side rather than being squeezed into one square.
  • This pairs with pinning --clover-items-picture-height (currently Clover's 8rem, which is 152px against DC's 19px root) — the square's size comes straight off that variable.

@mathewjordan

mathewjordan commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

"View all" on the sliders should read as a link, not a filled pill

As it stands the pill sits awkwardly next to the work page's other controls — measured on /items/e34b2f42-07ac-40bc-9609-395346fa4f7f (DC root font 19px):

control height how the height is made
"Show More" (Expand → Button) 42.5px font-size: 17px, line-height: 1, padding: 0.75em 1em, inline-flex + align-items: center
"View all" (.clover-items-homepage) 26.6px line-height: 1.4rem alone — padding: 0 var(--dc-space-legacy-3), no vertical padding, display: block

Rather than growing the pill to match the button, drop the pill and style it as a text link. It is a navigational affordance in a section header, not an action, and DC already has a house pattern for exactly that: SectionHeading's "View Collections →" on the homepage (.sectionHeadingExplore in components/Shared/SectionHeading.module.css) — purple link text with a forward arrow, aligned against the section heading.

That means removing the fill, the white text and the radius from SliderWrapper.module.css:

/* current */
.styledSliderIIIFWrapper :global(.clover-items-homepage) {
  padding: 0 var(--dc-space-legacy-3);
  border-radius: 38px;
  background-color: var(--dc-color-purple);
  color: var(--dc-color-white);
  font-size: var(--dc-font-size-gr3);
  line-height: 1.4rem;
  text-decoration: none;
}

and letting it inherit the site's link treatment instead, matching .sectionHeadingExplore's display: flex; align-items: center; height: var(--dc-size-gr4).

One constraint worth knowing: Clover renders the header link as bare text —

<a className="clover-items-homepage" href={heading.homepage}>{t("commonViewAll")}</a>

— with no icon slot, so if the forward arrow is wanted to complete the match with SectionHeading, it has to come from a ::after (glyph or background SVG) rather than from markup.

This supersedes the height-matching suggestion in my earlier comment.

@mathewjordan mathewjordan left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note comments. Thanks for chatting it through @kdid. In additional be sure to update to latest. Sorry for the moving target.

@kdid

kdid commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@mathewjordan - Here's what's addressed in the latest push:

Clover 4.9.2

  • Pinned @nulib/clover to exact 4.9.2. I read the changelog from 4.4.2 forward: the .clover-* classes and --clover-* properties we target are unchanged. The content-search fix from 4.5.0 is included: a search opened with searchQuery now stays on the content state's canvas.

Download and Share crashes

  • A/V works: Clover 4 writes a FragmentSelector (t=12.34) instead of Clover 3's PointSelector.t. A new selectorStartTime helper reads both, including ranges (t=12,30) and npt:. convertTime now returns an empty string instead of throwing on a non-numeric value. Image works still offer "Zoom to current view".
  • Image works (found while testing): when there's no region or time to keep, Clover 4 targets the bare Canvas (target: { id, type: "Canvas" }) rather than { source, selector }. getContentStateMetadata only read target.source.id, so it crashed on annotationBody.items. This has been there since the move to Clover 4 (4.4.2 writes the same target).
    • A new getContentStateCanvasId handles a bare Canvas, a SpecificResource, a URI string with a fragment, and a list of targets.
    • The annotationBody lookup is now guarded, so a canvas missing from the manifest no longer crashes the dialog.
    • The WebMCP selectedCanvasId uses the same helper.

Related-items sliders

  • Arrows centred on the image: --clover-items-height is set to the card width using container query units on .clover-items-frame. The arrows and the edge shades now centre on the picture.
  • Arrows hang off the edges: they sit half outside the slider at 1160px and wider, and inset below that. I used 1160 rather than 1120 because half the 42.5px arrow has to fit past the 19px gutter, plus room for a classic scrollbar, without causing a horizontal page scroll.
  • Clamped-title popover: styled like "View as IIIF": white, 3px radius, 5px 5px 19px 0 #0002 shadow.
  • "View all": now a purple text link with the forward arrow, matching "View Collections →" (same 19px text and arrow size). Clover renders the link as bare text, so the arrow is a ::after mask of IconArrowForward. The header row is centred like SectionHeading.
  • Columns and gap (from our conversation): up to 5 across (the 6-across step at 1439px is gone). Cards are 20px apart (--dc-space-legacy-4) at every width. One variable sets both the card gap and the space under the subheading.

Viewer thumbnail rail

  • Thumbnail height pinned to 128px (Clover's default 8rem was 152px against our 19px root).
  • Each thumbnail keeps its own width, between a square and twice its height, and is cropped to fill (object-fit: cover), so no background shows. A 6:1 tape still is 256px wide, a tall brochure page is a 128px square, and a 3:2 photo keeps its proportions at 192px.
  • The width is set on each picture rather than the whole thumbnail, so a canvas with several images still shows them side by side.

Tests and docs

  • New unit tests: time-helpers, content-state-helpers, and the Download and Share content-state dialog (video time, image region, bare Canvas target).
  • tests/styles-migration.spec.ts now checks:
    • rail thumbnail sizes and cropping
    • arrow centring, the overhang, and no horizontal page overflow
    • 5 across up to 1920px
    • the card gap equals the space under the subheading
    • the "View all" link styling
  • AGENTS.md and DESIGN.md are updated for @nulib/clover 4.9.2.
  • Jest (84 suites) and tsc pass. The Playwright styles spec passes in Chromium and Firefox locally; WebKit runs in CI.

@mathewjordan
mathewjordan self-requested a review November 11, 2026 21:15

@mathewjordan mathewjordan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@kdid
kdid merged commit a0ecc4a into deploy/staging Nov 11, 2026
@kdid
kdid deleted the preview/clover-4 branch November 11, 2026 21:19
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.

3 participants