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: flatten _singletons and increase usage of sanity/_createContext #7311

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

ricokahler
Copy link
Contributor

@ricokahler ricokahler commented Aug 3, 2024

Description

This one is a follow up for @stipsan's #7160.

This PR:

  • Flattens the _singletons folder structure. Previously, this folder mirrored our core folder structure, but this nesting was unnecessary given the global nature of these React contexts. Each context has a single, global key and is exported from 'sanity/_singletons'. Flattening the structure should simplify things and improve discoverability of contexts, and aligns the file system organization with how these contexts are used and exported.
  • Refactors all usages of createContext from 'react'tosanity/_createContext. This should prevent errors due to pnpm installing the same version of 'sanity'` more than once.
  • Updates the ESLint rule to disallow importing createContext from 'react'

NOTE: review the last commit for an easier review

What to review

Did I miss anything? Does everything look alright?

I wrote a small script for this refactor.

Testing

Ran type check and ensured all of the previous contexts that were exported were still being exported.

Notes for release

  • Refactored singleton contexts to use sanity/_createContext, reducing potential "missing context" errors in certain environments.

Copy link

vercel bot commented Aug 3, 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 Aug 3, 2024 3:18am
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 3:18am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 3:18am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 3:18am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 3:18am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Aug 3, 2024 3:18am

Copy link
Contributor

github-actions bot commented Aug 3, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Aug 3, 2024

Component Testing Report Updated Aug 3, 2024 3:25 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 42s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 30s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 37s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 17s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 10s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 3m 0s 0 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 43s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 45s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 13s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 9s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 25s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 17s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 14s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 1m 46s 30 0 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 19s 3 0 0

@ricokahler ricokahler added this pull request to the merge queue Aug 5, 2024
Merged via the queue into next with commit c512fa7 Aug 5, 2024
42 checks passed
@ricokahler ricokahler deleted the refactor/global-context branch August 5, 2024 15:25
cngonzalez pushed a commit that referenced this pull request Aug 20, 2024
…Context` (#7311)

* chore: add eslint rule to prevent react.createContext

* refactor: move and flatten contexts

* refactor: switch to sanity/_createContext
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