Phase 1: Feature Flag Setup
Effort: 1 hour Risk: None (no behaviour change) Priority: Required after Phase 0 (Type Audit) Previous: Phase 0: Type Audit Next: Phase 2: Split MainViewer Components
Goal
Set up infrastructure for safe refactoring using feature flags. At the end of this phase, you'll have two identical implementations (legacy and refactored) with the ability to toggle between them.
Prerequisites
Complete Phase 0: Type Audit first to ensure all types are correct before starting refactoring.
Steps
0.1 Add Toggle Definition
File: toggles/webapp/app/toggles.ts
export const toggles = {
// ... existing toggles ...
iiifViewerRefactored: {
id: 'iiifViewerRefactored',
title: 'IIIF Viewer - Refactored',
defaultValue: false,
description: 'Use refactored Item Viewer',
},
};0.2 Create New Context Structure
Create new context directory as content/webapp/contexts/ItemViewerContextV2/index.tsx by copying content/webapp/contexts/ItemViewerContext/index.tsx.
0.3 Rename Existing Components to .legacy.tsx
0.4 Create Wrapper Component
New file: content/webapp/views/pages/works/work/IIIFViewer/index.tsx
Important:
Legacy components import
ItemViewerContext, refactored components importItemViewerContextV2Dynamic imports are server-rendered by default -
NoScriptImagewill still work without JavaScriptDo NOT add
{ ssr: false }to the dynamic imports as this would break progressive enhancement
0.5 Create Initial .refactored.tsx Files
Copy legacy files to create refactored versions:
Update imports in .refactored.tsx files:
0.6 Verify No Behaviour Change
Critical: At this stage, both implementations should be identical.
Run:
yarn contentTest viewer on localhost with flag OFF (should use legacy)
Enable toggle in toggles dashboard:
/togglesTest viewer with flag ON (should use refactored - identical behaviour)
Confirm toggling between old/new works seamlessly
Test scenarios:
Navigate between canvases (thumbnails, arrows)
Toggle sidebar
Zoom in/out
Fullscreen mode
Download options
Restricted items
Checkpoint: No user-facing behaviour has changed. You've set up infrastructure with two identical implementations using different contexts.
Success Criteria
Met, though several were delivered under different names than planned - see the naming note in the README.
Next Steps
Once Phase 1 is complete and verified, proceed to:
Phase 2: Split MainViewer Components - Split MainViewer before context refactoring (cleaner architecture)
See also:
Migration Checklist - Detailed verification steps
Feature Flag Strategy - Why we use feature flags
Last updated