Implement GutenbergKit ViewModel Architecture#22087
Conversation
|
| App Name | WordPress |
|
| Flavor | Jalapeno | |
| Build Type | Debug | |
| Version | pr22087-9408799 | |
| Commit | 9408799 | |
| Direct Download | wordpress-prototype-build-pr22087-9408799.apk |
|
| App Name | Jetpack |
|
| Flavor | Jalapeno | |
| Build Type | Debug | |
| Version | pr22087-9408799 | |
| Commit | 9408799 | |
| Direct Download | jetpack-prototype-build-pr22087-9408799.apk |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #22087 +/- ##
=======================================
Coverage 39.43% 39.43%
=======================================
Files 2149 2149
Lines 101872 101872
Branches 15604 15604
=======================================
Hits 40177 40177
Misses 58126 58126
Partials 3569 3569 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
These are significant stability and comprehensibility improvements. Thank you for completing this! 🙇🏻♂️
I stepped through each commit individually. Each of the commits a very logical and sound. Thank you for organizing the commit history so well.
I tested the experimental editor by performing documented test cases. I did not encounter any regressions aside from the remote editor load failure noted in a sibling PR: #22086 (review).
ab161e3 to
a293fb3
Compare
fe43d49 to
ef8b42b
Compare
Replace the untyped Map<String, Any?> settings pattern with a proper data class for better type safety and cleaner code in GutenbergKitEditorFragment. Changes: - Add GutenbergKitSettings data class with all required properties and proper types - Use List<String> instead of Array<String> for better immutability and equals behavior - Update createGutenbergKitSettings() to return typed data class instead of Map - Replace generic getSetting<T>() helper methods with direct property access - Simplify buildEditorConfiguration() method using typed properties - Convert Lists to Arrays only when interfacing with external APIs (.toTypedArray()) - Add serialVersionUID for proper Serializable implementation Benefits: - Compile-time type safety instead of runtime casting - Clearer API contract and better IDE support - Eliminates potential ClassCastException errors - Better equals/hashCode behavior with Lists vs Arrays - More maintainable and readable code
Fixes Detekt SerialVersionUIDInSerializableClass violation by adding required serialVersionUID constant to the Serializable data class.
Replace problematic static variable pattern with proper ViewModel architecture for GutenbergKit editor settings management. Changes: - Create GutenbergKitViewModel with proper DI setup - Update EditPostActivity to initialize ViewModel and pass settings through it - Update GutenbergKitEditorFragment to observe ViewModel instead of Bundle/static settings - Remove Bundle serialization and static companion object settings variable - Add Dagger injection support for GutenbergKitEditorFragment - Fix dependency injection timing by triggering DI in onCreate() Benefits: - Eliminates memory leaks from static variables - Fixes WebViewGlobal serialization crashes - Enables proper lifecycle-aware state management - Provides foundation for reactive settings updates
Relocate GutenbergKitSettings data class from GutenbergKitEditorFragment to GutenbergKitViewModel for improved code organization and cohesion. Changes: - Move GutenbergKitSettings data class to GutenbergKitViewModel.kt - Update import statements in EditPostActivity and GutenbergKitEditorFragment - Co-locate data model with its managing ViewModel
Resolve linting issues identified by Detekt: - Remove unused import for GutenbergKitSettings in EditPostActivity - Fix spacing between imports and class declaration - Remove unused imports for WebViewGlobal and Serializable
Add a test to verify core functionality: - Test that updateEditorSettings correctly stores and exposes settings - Validates the primary use case of the ViewModel - Ensures settings can be retrieved after being set
ef8b42b to
9408799
Compare
|
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
The PR is not deployed, so that's not possible. |
This reverts commit 890d484.
* Revert "Implement GutenbergKit ViewModel Architecture (#22087)" (#22127) This reverts commit 890d484. * Fix `GutenbergKit` editor issues during dark mode toggle (#22135) * Remove isEditorStarted flag to fix content loss during activity restart The isEditorStarted flag was preventing editor reinitialization during activity restarts, but this caused content loss because: 1. Activity restart triggers new fragment creation 2. isEditorStarted gets reset to false in onDestroy() 3. startWithEditorSettings() gets called but always rebuilds from original data 4. Current editor content is lost instead of being preserved Root cause: The flag was designed to prevent duplicate initialization within a single fragment instance, but during activity restarts, we WANT the editor to reinitialize with the current content, not block reinitialization entirely. Changes: - Remove isEditorStarted field and related state management - Remove isEditorStarted checks in startWithEditorSettings() - Allow editor to reinitialize after activity restart - Fixes content loss during dark mode toggle * Fix double ViewPager setup during auth state changes Prevent duplicate editor initialization by: 1. Only calling fetchWpComCookies() if not already in Success state 2. Adding ViewPager state check to prevent duplicate setup 3. Using distinctUntilChanged() to prevent duplicate LiveData emissions 4. Consolidating Success handling logic in handleSuccessfulAuth() Changes: - Check auth state before calling fetchWpComCookies() - Add ViewPager adapter check with error logging for duplicate setup attempts - Add distinctUntilChanged() to auth state observer - Extract handleSuccessfulAuth() for consistent Success state handling - Remove debug logging from production code * Update translations * Update translations * Bump version number * Update WordPress metadata translations for 26.1 * Update Jetpack metadata translations for 26.1 --------- Co-authored-by: Oguz Kocer <oguzkocer@users.noreply.github.com>





Summary
Replaces static variable pattern in
GutenbergKitEditorFragmentwith properViewModelarchitecture to improve state management and prevent memory leaks.Key Changes
GutenbergKitViewModelwith dependency injectionViewModel-based state managementGutenbergKitEditorFragmentTechnical Benefits
ViewModelbest practices