For the complete documentation index, see llms.txt. This page is also available as Markdown.

RFC 086: IIIF Viewer Context Refactoring

Status: Phases 0-6 complete. Phase 7 (cleanup) is blocked on the itemViewerRefactor toggle being defaulted to ON for 1+ week. Estimated effort: 14-17 hours Last modified: 2026-09-15T10:31:29+00:00

Purpose

This folder contains a comprehensive plan to refactor the IIIF Viewer context to eliminate code duplication and centralise derived state calculations.

Key principle: Write automated tests BEFORE refactoring (test-first approach), then use manual testing for extra confidence.

Names in these documents vs the code

The phase documents were written before implementation, and use provisional names the code doesn't match. Translate as follows when following them:

In these documents
In the code

contexts/ItemViewerContextV2/

content/webapp/contexts/ItemViewerContext/refactored.tsx, with legacy.tsx beside it and index.tsx selecting between the two on the toggle

Component.legacy.tsx / Component.refactored.tsx

IIIFViewer/legacy/Component.tsx / IIIFViewer/refactored/Component.tsx - directories, not filename suffixes

iiifViewerRefactored toggle

itemViewerRefactor

currentCanvasIndex also never went onto the context: it would duplicate query.canvas, which is already there. Several documents list it as a context value - Phase 6 in particular is written on the assumption that it exists.

Table of Contents

Understanding the Problem

Approach

Implementation Phases

Reference

Quick Navigation

I want to understand the refactoring

Start with 01-overview.md

I want to implement Phase 3

Read 09-phase-3-canvas-data.md and Testing Guide

I want to see test examples

Go to Testing Guide for complete TypeScript test examples

I want the testing checklist

See 14-testing-strategy.md for automated test requirements and manual testing checklist

Key Principles

  1. Fix types first - Audit and fix all types before refactoring (Phase 0)

  2. Automated tests BEFORE refactoring - Build comprehensive test coverage first

  3. Feature flag everything - Safe rollout with instant rollback capability

  4. Crystal-clear naming - Use is..., has..., can..., should... patterns for booleans

  5. Test-first workflow - Green to Green refactoring (tests pass before and after)

  6. Manual tests as backup - Comprehensive checklist for extra confidence

  7. Context for shared state only - Only add to context if used by 2+ components or likely to be needed soon

  8. Hooks for complex logic - Extract to custom hooks for testability, even if only used once

  9. Split components with drastically different modes - See Future Improvements for details

Progress Tracking

Tickets are in wellcomecollection.org.

Two tickets sit outside the phase structure: #12984 (review and add tests) ran alongside Phases 0-2, and #13329 (readability/normalisation pass) alongside Phase 3. Out-of-scope findings picked up along the way are collected in #13273, which includes items to clear before the toggle can go on publicly.


Related Documentation:

Last updated