Skip to content

refactor!: rename MediaUploadDelegate to MediaProcessor - #630

Draft
jkmassel wants to merge 2 commits into
feat/remove-upload-file-hookfrom
refactor/media-processor-rename
Draft

refactor!: rename MediaUploadDelegate to MediaProcessor#630
jkmassel wants to merge 2 commits into
feat/remove-upload-file-hookfrom
refactor/media-processor-rename

Conversation

@jkmassel

@jkmassel jkmassel commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Stacked on #629. Seventh of ten PRs splitting #621. Mechanical — no behavior change.

What?

MediaUploadDelegateMediaProcessor, mediaUploadDelegatemediaProcessor, the server parameter → processor, the file → MediaHandlers.swift, and Android's demo → DemoMediaProcessor.

Why?

The protocol no longer uploads anything — #629 removed uploadFile, leaving handlesFile and processFile. "UploadDelegate" now describes the one thing it can't do, and next to MediaUploader the two names read as variations on the same job rather than the two halves of a deliberate split.

MediaProcessor says what is left: it transforms bytes, GutenbergKit delivers them.

How?

A rename sweep, ~83 sites across both platforms including the demo apps. Prose in doc comments follows the types. MediaHandlers.swift because the file holds both protocols now.

The weak_delegate suppression added in #625 goes away with the name: the rule was arguably right that a strongly-held "delegate" is a smell, and the answer was that this was never a delegate.

Following that through: MediaProcessor and MediaUploader also drop : AnyObject. Nothing needed class-boundness — there is no weak, ===, or ObjectIdentifier use against either protocol anywhere in the tree — and EditorViewController holds both strongly, so a class-bound protocol was quietly steering hosts toward a conformer that holds the view controller back and closes a retain cycle ARC cannot break. Dropping it lets a host conform with a value type capturing only what the work needs. Every existing conformer is a class and is unaffected.

Testing Instructions

  • swift test — host suite green
  • Android :Gutenberg:testDebugUnitTest green
  • iOS Simulator xcodebuild; Android demo compiles
  • SwiftLint + Detekt clean

Breaking change

mediaUploadDelegate is now mediaProcessor, and MediaUploadDelegate is MediaProcessor. Conformances need no changes beyond the name.

MediaProcessor and MediaUploader are also no longer AnyObject-bound. Class conformers are unaffected; a host that declared its own weak reference to one of these existentials would need to hold it strongly instead.

Note this relaxes a constraint rather than fixing the cycle outright — a struct that stores the EditorViewController cycles just the same. The doc comments say so rather than implying the type system settles it.

@wpmobilebot

wpmobilebot commented Sep 5, 2026

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/630")

Built from 976ade8

@jkmassel
jkmassel force-pushed the refactor/media-processor-rename branch from f6a9bac to 2a835c1 Compare September 8, 2026 16:12
The protocol no longer uploads anything — the previous commit removed
`uploadFile`, leaving `handlesFile` and `processFile`. "UploadDelegate" now
describes the one thing it can't do, and next to `MediaUploader` the two
names read as variations on the same job rather than the two halves of a
deliberate split.

`MediaProcessor` says what is left: it transforms bytes, GutenbergKit
delivers them. Mechanical throughout — the property becomes
`mediaProcessor`, the server parameter `processor`, the file
`MediaHandlers.swift` (it holds both protocols now), and Android's demo
`DemoMediaProcessor`. Prose follows the types.

The `weak_delegate` suppression added when the property became strong goes
away with the name: the rule was arguably right that a strongly-held
"delegate" is a smell, and the answer was that this was never a delegate.

BREAKING CHANGE: `mediaUploadDelegate` is now `mediaProcessor`, and
`MediaUploadDelegate` is `MediaProcessor`. Conformances need no changes
beyond the name.
`MediaProcessor` and `MediaUploader` were both `AnyObject`-bound, and
`EditorViewController` holds both strongly. A conformer that holds the view
controller back therefore closes a retain cycle ARC cannot break: the editor
is never freed, so `deinit` never runs, so `uploadServer.stop()` — its only
caller — never runs either, and a bound loopback `NWListener` outlives the
editing session.

Nothing needed class-boundness. There is no `weak`, `===`, or
`ObjectIdentifier` use against either protocol anywhere in the tree, and
every existing conformer is a class, which conforms unchanged. Dropping the
requirement lets a host conform with a value type capturing only what the
work needs — the shape that avoids the cycle, and the one a class-bound
`Delegate` discouraged.

This does not make the cycle impossible: a struct that stores the view
controller cycles just the same. The docs say so rather than implying the
type system settles it.
@jkmassel
jkmassel force-pushed the refactor/media-processor-rename branch from c450547 to 976ade8 Compare September 9, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android iOS [Type] Breaking Change For PRs that introduce a change that will break existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants