Skip to content

refactor: Fetch and cache GutenbergKit editor settings #24417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Apr 24, 2025

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Apr 5, 2025

Fetch and cache editor settings before providing them to the editor, as it
allows improving offline support. The changes also communicate the
background activity with an activity indicator.

Ref CMM-200.

Related:

To test:

Important

Ensure the following experimental features are enabled:

  • Experimental block editor
  • Experimental block editor styles

1: Initial editor fallbacks to default settings

  1. Enable airplane mode.
  2. Open the post editor.
  3. Verify the editor loads, using default settings—e.g., white background with black text.

2: Editor fetches site-specific settings

  1. Disable airplane mode.
  2. Open the post editor.
  3. Verify the editor loads with site-specific settings—e.g., the theme's background and foreground colors.

3: Editor fallback to cached settings

  1. Enable airplane mode.
  2. Open the post editor.
  3. Verify the editor loads with site-specific settings—e.g., the theme's background and foreground colors.

Regression Notes

  1. Potential unintended areas of impact
    Regressions in Gutenberg Mobile or Aztec editors.
  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manually smoke tested the editors.
  3. What automated tests I added (or what prevented me from doing so)
    Deemed unnecessary for the experimental editor.
    PR submission checklist:
  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@dangermattic
Copy link
Collaborator

dangermattic commented Apr 5, 2025

2 Warnings
⚠️ Modules/Package.swift was changed without updating its corresponding Package.resolved. Please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running swift package resolve).
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@dcalhoun dcalhoun changed the title feat: Provide GutenbergKit editor settings refactor: Provide GutenbergKit editor settings Apr 5, 2025
@dcalhoun dcalhoun force-pushed the feat/provide-editor-settings branch from 7cdf99a to 9ceb20e Compare April 9, 2025 19:13
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 9, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number27516
VersionPR #24417
Bundle IDorg.wordpress.alpha
Commit487ede4
Installation URL5qc7k318n5vjo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 9, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number27516
VersionPR #24417
Bundle IDcom.jetpack.alpha
Commit487ede4
Installation URL2klik7q580q4g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@dcalhoun dcalhoun added [Type] Enhancement Gutenberg Editing and display of Gutenberg blocks. labels Apr 9, 2025
@dcalhoun dcalhoun force-pushed the feat/provide-editor-settings branch from 9ceb20e to 80f864d Compare April 11, 2025 14:59
@dcalhoun dcalhoun changed the title refactor: Provide GutenbergKit editor settings refactor: Fetch and cache GutenbergKit editor settings Apr 11, 2025
@dcalhoun dcalhoun marked this pull request as ready for review April 12, 2025 01:14
@dcalhoun dcalhoun requested a review from jkmassel April 12, 2025 01:15
}

@MainActor
func fetchSettings() async throws -> [String: Any] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we've never fetched the settings and the network connection fails?

In my testing it seems like it'll just show a spinner forever?

If we don't have locally cached settings and the network request fails we should probably:

  1. Try again some number of times (maybe 2?)
  2. Show an error message

I could see an argument for showing some kind of editor with no remote settings, but I don't know how feasible that is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your experience is surprising. These changes were built to accomplish what you describe. When I block the network request (via Charles Proxy) for the editor settings, the editor continues to load with default editor settings after a moment.

How are you causing the network connection failure in your testing?

The screen recording below showcases both the default settings and site-specific settings.

Screen.Recording.2025-04-16.at.16.44.12.mov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the situation you describe is a part of the testing instructions in the PR description. 😄 I'm perplexed as to why you may be experiencing a different outcome.

@dcalhoun dcalhoun force-pushed the feat/provide-editor-settings branch from d26a943 to c8aa2cf Compare April 17, 2025 18:47
@dcalhoun dcalhoun requested a review from jkmassel April 18, 2025 17:00
@jkmassel
Copy link
Contributor

So it's not forever, but it is almost 5 minutes:

gutenbergkit-measure_editor-first-render: 298.35688507556915

I can consistently repro this by enabling the Network Link Conditioner (on a real device), setting it to "Very Bad Network", then running this PR on that device and following the testing instructions.

I suspect we can resolve the issue by putting a timeout on how long we wait for the remote network settings (I'd suggest 5 seconds – IINM, the connection timing out should automatically cause the "whoops, we couldn't load editor settings" dialog.

dcalhoun added 12 commits April 24, 2025 11:22
This reverts commit e4ec71b6c77e2439e9d98c0273f9bdcff64d098f.
This reverts commit 39ac9caf71089853e5f256697f4882cc55d2bffd.
Remove unnecessary completion handler structure.
Improve editor start performance.
The cache was discarded each time the editor closed, which defeats the
purpose of the cache. We must store it somewhere outside the editor view
controller.
dcalhoun added 10 commits April 24, 2025 11:22
Avoid sending both foreground and background requests.
Revalidating the cache on each editor launch will ensure the latest
settings are available.
Improve load speed of editor.
This conditional was overlooked when the local experimental feature
toggle was augmented with a remote feature flag for roll out control.

#24465
Avoid postponing the editor start for longer than three seconds. We
instead present the editor without any site-specific settings.
@dcalhoun dcalhoun force-pushed the feat/provide-editor-settings branch from f294279 to e8a892c Compare April 24, 2025 15:22
Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having discussed this in Slack, it seems this is as good as it'll get for now. We can control the settings loading prior to the editor being displayed, but unfortunately there's no UI inside the editor to show the other network operations that are happening.

This looks solid, and should work well in the vast majority of cases – if someone's network is this bad they're probably having a hard time using the app anyway.


Task { @MainActor in
// Start the editor with default settings after 3 seconds
let timeoutTask = Task {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever way to address this – I think ideally we'd just use the timeout property on URLRequest, but we don't really own WordPressOrgRestApi. I guess we'll come back to this when it's time to adopt the Rust-layer REST API, and we can switch it over then.

@dcalhoun
Copy link
Member Author

[...] unfortunately there's no UI inside the editor to show the other network operations that are happening.

Long term, I believe we can improve the experience with WebView-driven UI so that it display a "skeleton" while additional requests complete.

That said, it gets complicated for the remote/site-specific editor. That editor fetches its React library (used for composing UI)—do we await React or build skeleton UI without React? We likely do the latter, and we can also finish implementing cached bundles to further improve the loading experience.

Copy link

@dcalhoun dcalhoun added this pull request to the merge queue Apr 24, 2025
Merged via the queue into trunk with commit d82fdd4 Apr 24, 2025
32 of 34 checks passed
@dcalhoun dcalhoun deleted the feat/provide-editor-settings branch April 24, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks. [Type] Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants