Remove WordPressData's WordPressUI and WordPressSharedUI dependencies - #25832
Remove WordPressData's WordPressUI and WordPressSharedUI dependencies#25832jkmassel wants to merge 2 commits into
Conversation
ManagedPerson was the only file in WordPressData importing WordPressUI, and the one symbol that looked like it needed it — AvatarURL.canonicalURL — is Gravatar's, already imported directly in the same file. Drop the import and the package dependency.
RichContentFormatter is plain String -> String HTML sanitizing, but it lived in WordPressSharedUI, so WordPressData pulled in the UI layer to use it. Move the eight platform-independent methods and the RegEx table down to WordPressShared; keep formatContentString and resizeGalleryImageURL — which read UIScreen and call PhotonImageURLHelper — in WordPressSharedUI as an @objc extension. WordPressData no longer depends on WordPressSharedUI. The text-formatting tests move with the code and now run on macOS under swift test; the gallery-resize test stays iOS-only.
Generated by 🚫 Danger |
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 33405 | |
| Version | PR #25832 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 2473db9 | |
| Installation URL | 58ceofc2ftspg |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 33405 | |
| Version | PR #25832 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 2473db9 | |
| Installation URL | 2lmc0p9pkr5fo |


Description
WordPressDatais a Core Data model layer, but it depended on two UI modules —WordPressUIandWordPressSharedUI. Neither dependency was necessary. This removes both.Note
Two commits, reviewable independently:
Remove dead WordPressUI import from WordPressData, thenSplit RichContentFormatter out of WordPressSharedUI.import WordPressUIfromManagedPersonand dropWordPressUIfromWordPressData's package dependencies.RichContentFormatterso its platform-independent text methods move down toWordPressShared, and dropWordPressSharedUIfromWordPressData's package dependencies.Splitting
RichContentFormatterRichContentFormattersanitizes post and comment HTML — stripping forbidden tags and inline styles, normalizing paragraphs, tidying Gutenberg galleries. It's plainString → Stringtext work, but it lived inWordPressSharedUI, so everything that used it — includingWordPressData— pulled in the UI layer.Only two of its methods actually need that layer:
resizeGalleryImageURLreads the screen (UIScreen.main) to size gallery images and callsPhotonImageURLHelperfromWordPressSharedObjCUI, andformatContentStringchains through it. Those two move to a newRichContentFormatter+DisplayPipeline.swiftinWordPressSharedUI, as an@objcextension on the class. The other eight methods and theRegExtable move toWordPressShared.ObjC callers see no change.
RichContentFormatteris still one@objcclass.CommentService.malready@imports bothWordPressSharedandWordPressSharedUI, soremoveTrailingBreakTags(now inWordPressShared) andformatContentString(theWordPressSharedUIcategory) both resolve.WordPressData'sReaderPost+Mappinggets the pure methods fromWordPressShared, which it already imported.The tests move with the code:
RichContentFormatterTestsis nowWordPressShared-only and runs on macOS underswift test; the single gallery-resize test stays iOS-only in the newRichContentFormatterUITests.The
WordPressUIimport was deadManagedPersonwas the only file inWordPressDataimportingWordPressUI, and the one symbol that looked like it needed it —AvatarURL(url:)?.canonicalURL— belongs to the Gravatar SDK, which the file already imports directly.WordPressUIsupplied nothing.What I considered
The alternative was to move the whole class to
WordPressSharedand gateresizeGalleryImageURLbehind#if canImport(UIKit), givingWordPressShareda conditional dependency onWordPressSharedObjCUIfor the Photon helper. Rejected: that pushes a UI-only ObjC dependency down into the base shared module — a layering inversion in the other direction — and scatters#ifscaffolding through shared code. Keeping the screen- and Photon-dependent methods in the UI layer is where they belong. (WPImageURLHelper, the other helperresizeGalleryImageURLuses, was already inWordPressShared.)Not in this PR
This removes
WordPressData's two direct edges to the UI modules. It does not makeWordPressDatabuild on macOS on its own — it still importsUIKitandMobileCoreServicesdirectly, and pullsWordPressSharedUItransitively throughFormattableContentKiton iOS. Those are separate changes.Testing instructions
Verified locally:
swift test --filter RichContentFormatterTests(macOS host) — 7 text-formatting tests pass. They previously couldn't run on macOS (excluded because the file importedWordPressSharedUI); they're now in the cross-platform set.swift build --build-tests(macOS host) —WordPressSharedcompiles with the moved code.xcodebuild -scheme WordPressData -destination 'generic/platform=iOS Simulator' build—BUILD SUCCEEDED, withWordPressSharedUIno longer inWordPressData's dependency graph.WordPressSharedUIbuilds with the new extension;formatContentStringandresizeGalleryImageURLappear in the generatedWordPressSharedUI-Swift.h, so the@objccross-module category is visible to ObjC.Verified at runtime (Jetpack, iOS 26 simulator). The sanitization logic is a byte-identical
git mv, so its behavior is covered by the unit tests above — these two checks confirm the thing the move actually changes: that the relocated class and its cross-module@objccategory link, load, and dispatch in the running app.WordPressData→WordPressShared(Swift). Opened a post whose content carries a Jetpack tiled gallery, a grid built entirely from inlineflex-basisstyles the app has no CSS fallback for. It renders as a single full-width column (24 images, each at the full content width) — the inline styles are stripped — soremoveInlineStylesresolves and runs from its new module. (toadilymagical.wordpress.compost 347)CommentService→ the cross-module@objcformatContentString. Opened a post with a comment; loading it ranmergeHierarchicalComments → sanitizeCommentContent → [RichContentFormatter formatContentString:isPrivateSite:]and the comment rendered, with no unrecognized-selector crash. This confirms the@objccategory — defined inWordPressSharedUIon the class that now lives inWordPressShared— registers and dispatches at load time, the one behavior a successful compile implies but doesn't prove. (WordPress.com News "WordCamp US 2026" post)