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

fix(core): inherit readOnly state from ancestors in copyPaste function #7643

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

pedrobonamin
Copy link
Contributor

@pedrobonamin pedrobonamin commented Oct 21, 2024

Description

When pasting values into a field which inherits the readOnly from the parent this was not verified., so it was possible to paste into read only fields.

This PR adds a function resolveReadOnlyAncestor to check if any ancestor of the path in which the user is pasting is read only, if it is, it won't allow pasting.

E.g, pasting into inheritedReadOnlyField was allowed, the same is happening with arrays.

    {
      name: 'readOnlyObject',
      title: 'Read only object',
      type: 'object',
      readOnly: true,
      fields: [
        {
          name: 'selfDefinedReadOnlyField',
          title: 'Read only field',
          description: 'ReadOnly defined in field',
          type: 'string',
          readOnly: true,
        },
        {
          name: 'inheritedReadOnlyField',
          title: 'Read only field',
          description: 'ReadOnly inherited from object',
          type: 'string',
        },
      ],
    }
Screen.Recording.2024-10-21.at.18.11.24.mov

What to review

Is the implementation correct? Accessing the parents using the resolveReadOnlyAncestor is that in line with the existing approaches?

Testing

New tests have been added into the copy paste to guard this functionality.
You can test it manually visiting https://test-next-studio-git-sdx-1643.sanity.dev/test/structure/input-standard;objectsTest;0689d2c6-5305-42e5-b381-32c335b3fd60 and trying to copy-paste values into the disabled fields

Notes for release

fixes an issue in copy paste in which the readOnly state was not correctly inherited to the children fields.

@pedrobonamin pedrobonamin requested a review from a team as a code owner October 21, 2024 16:15
@pedrobonamin pedrobonamin requested review from binoy14 and sjelfull and removed request for a team and binoy14 October 21, 2024 16:15
Copy link

vercel bot commented Oct 21, 2024

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

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 8:35am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 8:35am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 8:35am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 8:35am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Oct 22, 2024 8:35am
page-building-studio ⬜️ Skipped (Inspect) Oct 22, 2024 8:35am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Oct 21, 2024

Component Testing Report Updated Oct 22, 2024 8:31 AM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 45s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 31s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 38s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 11s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 2m 33s 1 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 45s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 41s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 17s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 8s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 26s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 36s 12 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

Copy link
Contributor

github-actions bot commented Oct 21, 2024

⚡️ Editor Performance Report

Updated Tue, 22 Oct 2024 08:34:15 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 16.7 efps (60ms) 17.9 efps (56ms) -4ms (-6.7%)
article (body) 63.7 efps (16ms) 63.1 efps (16ms) +0ms (-/-%)
article (string inside object) 19.2 efps (52ms) 19.2 efps (52ms) +0ms (-/-%)
article (string inside array) 14.5 efps (69ms) 15.0 efps (67ms) -3ms (-3.6%)
recipe (name) 27.8 efps (36ms) 27.8 efps (36ms) +0ms (-/-%)
recipe (description) 32.3 efps (31ms) 31.3 efps (32ms) +1ms (+3.2%)
recipe (instructions) 99.9+ efps (7ms) 99.9+ efps (7ms) +0ms (-/-%)
synthetic (title) 14.5 efps (69ms) 14.8 efps (68ms) -2ms (-2.2%)
synthetic (string inside object) 14.9 efps (67ms) 15.4 efps (65ms) -2ms (-3.0%)

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) 60ms 68ms 86ms 215ms 537ms 15.3s
article (body) 16ms 17ms 27ms 95ms 140ms 5.9s
article (string inside object) 52ms 57ms 80ms 254ms 425ms 8.6s
article (string inside array) 69ms 72ms 81ms 207ms 959ms 9.6s
recipe (name) 36ms 39ms 53ms 94ms 3ms 10.2s
recipe (description) 31ms 33ms 35ms 144ms 0ms 6.3s
recipe (instructions) 7ms 9ms 10ms 21ms 0ms 3.5s
synthetic (title) 69ms 75ms 86ms 324ms 1570ms 15.6s
synthetic (string inside object) 67ms 69ms 87ms 582ms 1660ms 10.2s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 56ms 62ms 69ms 203ms 309ms 14.8s
article (body) 16ms 18ms 21ms 189ms 236ms 5.3s
article (string inside object) 52ms 57ms 66ms 210ms 223ms 8.7s
article (string inside array) 67ms 71ms 73ms 311ms 885ms 9.4s
recipe (name) 36ms 39ms 56ms 77ms 31ms 9.8s
recipe (description) 32ms 34ms 38ms 73ms 11ms 6.2s
recipe (instructions) 7ms 9ms 10ms 33ms 0ms 3.4s
synthetic (title) 68ms 70ms 78ms 153ms 915ms 14.4s
synthetic (string inside object) 65ms 71ms 89ms 356ms 1519ms 10.4s

📚 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.

sjelfull
sjelfull previously approved these changes Oct 21, 2024
Copy link
Member

@sjelfull sjelfull left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@pedrobonamin pedrobonamin added this pull request to the merge queue Oct 22, 2024
Merged via the queue into next with commit 4298fe0 Oct 22, 2024
67 checks passed
@pedrobonamin pedrobonamin deleted the sdx-1643 branch October 22, 2024 12:01
bjoerge added a commit that referenced this pull request Oct 23, 2024
* next:
  v3.62.0
  fix: warnings on React 19 (#7654)
  fix(deps): update dependency @sanity/ui to ^2.8.10 (#7652)
  fix(deps): update dependency @sanity/ui to ^2.8.10 (#7653)
  chore(deps): update dependency @sanity/visual-editing to v2.2.2 (#7651)
  fix(core): inherit readOnly state from ancestors in copyPaste function (#7643)
  fix(deps): update dependency @sanity/mutate to ^0.10.1 (#7650)
  fix(deps): Update dev-non-major (#7649)
  fix(deps): update dependency @sanity/presentation to v1.17.3 (#7648)
  fix(deps): update dependency @portabletext/editor to ^1.1.5 (#7638)
  fix(deps): update dependency @sanity/presentation to v1.17.2 (#7647)
  fix(deps): Update dev-non-major (#7646)
  fix(deps): update dependency @sanity/presentation to v1.17.1 (#7645)
  chore(deps): update dependency @sanity/preview-url-secret to v2 (#7641)
  fix(deps): update dependency @sanity/presentation to v1.17.0 (#7640)
  fix(deps): Update dev-non-major (#7639)
  chore(cli): update help copy for deploy command (#7624)
  chore(test-studio): add asset types to structure navigation (#7631)
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