Skip to content
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

refactor(core): replace PortableTextEditor with EditorProvider #8040

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

christianhg
Copy link
Member

@christianhg christianhg commented Dec 13, 2024

Description

EditorProvider is the new way of setting up the Portable Text Editor. It's
going to be the way we document how to use standalone PTE and it's the way
Create already uses PTE.

It exposes all the new APIs that have been under development, and for now it's
also 100% backwards compatible by the fact that:

  1. No types or interfaces have been removed.
  2. The old usePortableTextEditor() and usePortableTextEditorSelection()
    hooks are still exposed.
  3. Static methods like PortableTextEditor.addAnnotation(...) still work (even
    though the PortableTextEditor React class isn't used to instantiate the
    editor anymore.)
  4. You can hand-roll custom "plugins" to achieve backwards compatible
    behaviours like listening for a value prop change or forwarding a ref to
    the PortableTextEditor instance.

This means that this change is a pure refactor that introduces no changes in
functionality and no downstream breaking changes for customers configuring PTE.

What to review

Does the code make sense and does everything PTE-related still work 👀

Testing

Existing test suite should be able to verify that things still work.

Notes for release

n/a

Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 3:49pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 3:49pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 3:49pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 3:49pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Dec 18, 2024 3:49pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Dec 13, 2024

⚡️ Editor Performance Report

Updated Wed, 18 Dec 2024 15:47:35 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 21.5 efps (47ms) 21.5 efps (47ms) +0ms (-/-%)
article (body) 56.2 efps (18ms) 56.3 efps (18ms) -0ms (-0.3%)
article (string inside object) 22.2 efps (45ms) 21.3 efps (47ms) +2ms (+4.4%)
article (string inside array) 20.0 efps (50ms) 21.3 efps (47ms) -3ms (-6.0%)
recipe (name) 43.5 efps (23ms) 47.6 efps (21ms) -2ms (-8.7%)
recipe (description) 50.0 efps (20ms) 50.0 efps (20ms) +0ms (-/-%)
recipe (instructions) 99.9+ efps (6ms) 99.9+ efps (6ms) +0ms (-/-%)
synthetic (title) 18.5 efps (54ms) 19.2 efps (52ms) -2ms (-3.7%)
synthetic (string inside object) 19.2 efps (52ms) 18.5 efps (54ms) +2ms (+3.8%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 47ms 70ms 84ms 384ms 610ms 12.0s
article (body) 18ms 20ms 41ms 203ms 258ms 6.1s
article (string inside object) 45ms 47ms 67ms 122ms 260ms 7.5s
article (string inside array) 50ms 55ms 74ms 187ms 323ms 8.0s
recipe (name) 23ms 25ms 30ms 48ms 0ms 7.5s
recipe (description) 20ms 21ms 22ms 32ms 0ms 4.8s
recipe (instructions) 6ms 8ms 9ms 9ms 0ms 3.2s
synthetic (title) 54ms 56ms 62ms 283ms 537ms 12.8s
synthetic (string inside object) 52ms 60ms 64ms 475ms 963ms 8.2s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 47ms 73ms 101ms 629ms 1203ms 12.6s
article (body) 18ms 21ms 31ms 120ms 151ms 6.0s
article (string inside object) 47ms 50ms 52ms 238ms 348ms 7.6s
article (string inside array) 47ms 49ms 57ms 184ms 147ms 7.6s
recipe (name) 21ms 22ms 24ms 45ms 0ms 7.5s
recipe (description) 20ms 21ms 23ms 41ms 0ms 4.7s
recipe (instructions) 6ms 8ms 9ms 18ms 0ms 3.2s
synthetic (title) 52ms 58ms 70ms 339ms 789ms 13.8s
synthetic (string inside object) 54ms 60ms 67ms 282ms 972ms 8.7s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

@christianhg christianhg force-pushed the refactor-pte-use-editor-provider branch from 67776c1 to 71409b1 Compare December 16, 2024 11:58
@christianhg christianhg changed the base branch from next to renovate/portabletext-editor-1.x December 16, 2024 11:58
@christianhg christianhg marked this pull request as ready for review December 16, 2024 11:59
@christianhg christianhg requested a review from a team as a code owner December 16, 2024 11:59
@christianhg christianhg requested review from rexxars and removed request for a team December 16, 2024 11:59
Copy link
Contributor

github-actions bot commented Dec 16, 2024

Component Testing Report Updated Dec 18, 2024 3:44 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 14s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 14s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 41s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 56s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 29s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 16s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 30s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 1m 15s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 37s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 48s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 14s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 29s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 53s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

bjoerge
bjoerge previously approved these changes Dec 18, 2024
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

This is great! Love to see different concerns being split into separate blocks like this. Thank you @christianhg!

`EditorProvider` is the new way of setting up the Portable Text Editor. It's
going to be the way we document how to use standalone PTE and it's the way
Create already uses PTE.

It exposes all the new APIs that have been under development, and for now it's
also 100% backwards compatible by the fact that:

1. No types or interfaces have been removed.
2. The old `usePortableTextEditor()` and `usePortableTextEditorSelection()`
   hooks are still exposed.
3. Static methods like `PortableTextEditor.addAnnotation(...)` still work (even
   though the `PortableTextEditor` React class isn't used to instantiate the
   editor anymore.)
3. You can hand-roll custom "plugins" to achieve backwards compatible
   behaviours like listening for a `value` prop change or forwarding a ref to
   the `PortableTextEditor` instance.

This means that this change is a pure refactor that introduces no changes in
functionality and no downstream breaking changes for customers configuring PTE.
@christianhg
Copy link
Member Author

This is great! Love to see different concerns being split into separate blocks like this. Thank you @christianhg!

I'm really happy to hear that! Unfortunately, I had to resolve a merge conflict so I'll need one more approval before this can get merged.

@christianhg christianhg added this pull request to the merge queue Dec 18, 2024
Merged via the queue into next with commit 5d1ed22 Dec 18, 2024
30 of 35 checks passed
@christianhg christianhg deleted the refactor-pte-use-editor-provider branch December 18, 2024 15:37
bjoerge added a commit that referenced this pull request Dec 19, 2024
* next: (68 commits)
  fix(deps): update dependency @sanity/icons to ^3.5.5 (#8105)
  fix(deps): update dependency @sanity/ui to ^2.10.12 (#8108)
  fix(deps): update dependency react-rx to ^4.1.10 (#8109)
  chore(deps): update dependency @sanity/tsdoc to v1.0.153 (#8107)
  chore(deps): update typescript-tooling (#8104)
  fix(deps): update dependency @sanity/icons to ^3.5.5 (#8106)
  feat(typegen): add support for astro (#8098)
  chore(deps): update dependency turbo to ^2.3.3 (#8099)
  fix(deps): Update dev-non-major (#8100)
  fix: `WebSocket is closed before the connection is established` warning (#8042)
  v3.68.1
  fix(deps): update dependency @sanity/presentation to v1.19.13 (#8102)
  v3.68.0
  fix: use consistent `framer-motion` semver range (#8094)
  refactor(core): replace `PortableTextEditor` with `EditorProvider` (#8040)
  fix: improve `SanityDefaultPreview` memoization (#8049)
  fix: tooltip position in announcements popup (#8092)
  fix: replace useMemo with useState (#8095)
  fix: replace unsafe `useMemo` with `useState` (#8047)
  fix: replace `React.createElement` with jsx runtime (#8043)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants