Fix GutenbergKit editor issues during dark mode toggle#22135
Fix GutenbergKit editor issues during dark mode toggle#22135oguzkocer merged 2 commits intorelease/26.1from
GutenbergKit editor issues during dark mode toggle#22135Conversation
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
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
|
|
| App Name | WordPress |
|
| Flavor | Jalapeno | |
| Build Type | Debug | |
| Version | pr22135-c010176 | |
| Commit | c010176 | |
| Direct Download | wordpress-prototype-build-pr22135-c010176.apk |
|
| App Name | Jetpack |
|
| Flavor | Jalapeno | |
| Build Type | Debug | |
| Version | pr22135-c010176 | |
| Commit | c010176 | |
| Direct Download | jetpack-prototype-build-pr22135-c010176.apk |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/26.1 #22135 +/- ##
================================================
+ Coverage 39.43% 39.74% +0.30%
================================================
Files 2149 1572 -577
Lines 101872 73737 -28135
Branches 15604 11925 -3679
================================================
- Hits 40177 29306 -10871
+ Misses 58126 41912 -16214
+ Partials 3569 2519 -1050 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dcalhoun
left a comment
There was a problem hiding this comment.
Thank you for helping to identify and land this fix. 🙇🏻♂️
I tested Simple and Atomic sites, private and public sites, appearance changes, orientation changes, and smoke tested editor functionality. The changes function well overall.
I did note an apparent race condition or memory leak may remain. I am able to discard the editor content after several OS appearance toggles.
Discard editor contents w/ multiple appearance toggles
Screen_Recording_20250815_074141_Jetpack.mp4
However, this appears present in 26.0 as well. Given that, I believe we should move forward with this fix; it's a definite improvement for the release branch. We can then spend time later seeking to address the core issue.
In the future, I envision us addressing two separate things:
- Optimize editor create/destroy logic to mitigate race conditions and memory leaks
- Manage
uiModeconfiguration changes similar to how we handle other configuration changes (e.g., device orientation change)
The second will be easier once GBK has its own separate activity, where we can make changes without impacting the other editors.
* 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
* 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
Fixes content loss and WebView loading issues when toggling dark mode while using the GutenbergKit editor.
Problem
isEditorStartedflag preventing proper reinitializationSolution
fetchWpComCookies()calls by checking existing auth statedistinctUntilChanged()to prevent duplicate LiveData emissionsisEditorStartedflag that was preventing proper editor reinitializationDemo
dark_mode_toggle_fixed.webm
Testing Instructions
Prerequisites
Test Cases
Dark Mode Toggle Test
Device Rotation Test (Regression Test)
Expected Results