v3.0.0-dev-preview.22 #3787
hermanwikner
announced in
Announcements
Replies: 1 comment 4 replies
-
spinning up this morning, getting this error:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
NOTE: with this release we highly recommend to upgrade
@sanity/ui
in package.json to:✨ Highlights
At-a-glance
This version introduces several breaking changes that we are really excited to share with everyone:
sanity
package and exportsSchema
namespaceThese changes will make the Studio's customization API easier to discover and will vastly improve DX when implementing plugins and customizations moving forward.
NOTE: This release vastly reduces the number of breaking changes that will be introduced as we are getting closer to the first official stable v3 release.
Components API
We have made changes to the new Components API that allows a lot more flexibility in terms of wrapping, replacing, and modifying components in the Studio.
These components are now available for customization:
Example:
The components available in this API are rendered using a middleware pattern. This means that plugin customizations are applied in a chain. Each plugin may call
props.renderDefault(props)
to defer to default rendering (this API wasnext(props)
in3.0.0-dev-preview.20
).What is
renderDefault
?The props for each component available in the API includes a callback function called
renderDefault
. As the name implies,renderDefault
renders the default component. When you callrenderDefault
, you also pass theprops
needed to render the default component, and these props can be modified. In the example below, we create a custom tool menu plugin that filters out the vision tool when the studio is running in non-development mode:If yet another plugin makes customizations of
toolMenu
– then the props received in that plugin will be the result of the previous customization (that is, no vision tool in non-development mode).NOTE: If
renderDefault
is not called, the middleware chain stops and the next plugin will have no effect.Using
renderDefault
in schemaThe
renderDefault
function may also be used directly in a schema definition to render a default component. In the example below, we create a component that renders the default string input with a character counter, directly in the schema:Result:
Consolidated
sanity
package and exportsBreaking changes to export bundles
The
sanity
package is now split up into these export bundles:sanity
sanity/cli
sanity/desk
sanity/router
There have been necessary changes made in order to make the exports clean and independent bundles: no API member is now exported twice (as was the case before). And there are no longer cyclic dependencies between exports.
sanity
sanity/_internal
sanity/_unstable
sanity
sanity/cli
sanity/desk
sanity/form
sanity
sanity/router
sanity
Why? These changes are mainly introduced to prevent API confusion.
This also means we have removed duplicate code in the export bundles, which could cause issues with React contexts and bundle size.
API release tags
All the API members in the
sanity
package now have API release tags. These are TSDoc release tags that are understood by Intellisense and can be seen in your IDE.Example:
How to reason about the various tags:
@internal
@alpha
@beta
@public
React 18
The Studio internals are upgraded to React 18 and use the new concurrent renderer. Support for React v17 is dropped and v18 is the new baseline in order to make full use of the new features and performance improvements.
Why we're doing this now
Structured content creation should be a delightful and exceptional experience. Everything should feel responsive. That means the UI needs to keep up with your interactions no matter what. If 300 people are editing the same document as you are and your phone's CPU just can't keep up that's ok. Everyone else's changes can wait for a second or two before they show up. As long as you can type as fast as you want without ever feeling held back by a sluggish text field that struggles to keep up with your thoughts. The edits of your peers have time to render whenever you stop to gather your thoughts. It's more important for you to stay in the zone, and for the studio to prioritize responding to your interactions.
With new APIs like
startTransition
,useTransition
,useDeferredValue
andSuspense
we can start moving towards making this vision a reality.While it is possible to do this in a way that gives theoretical support for both react
v17
andv18
, we ultimately decided against it after a thorough evaluation with the goal of maintaining compatibility withv17
. It came down to which option allow us to deliver the highest quality product, and unless everything is tested on both versions of react for every release we'll either:v17
support but unable to adoptv18
features that can't be shimmed onv17
. Such asstartTransition
,useTransition
anduseDeferredValue
.v18
support but thev17
becomes increasingly buggy and slow as devs become used to howv18
behaves. For examplev18
automatically batches state updates whilev17
does not. A component that inv18
have few re-renders might have a ton of re-renders inv17
if the component author isn't aware of this difference and there's greatv17
testing routines in place.Upgrade info
Official guide: https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis
If you're on react
v17
today and don't see any warnings in your console when running your studio locally then upgrading is pretty much just a matter of bumpingreact
,react-dom
andreact-is
to^18
in yourpackage.json
.Read the official upgrade guide to get a sense of what components you might need to give a little refactor.
While migrating studio internals we found that if there's a problem in a component it's usually related to one of these factors:
UNSAFE_
prefix, for exampleUNSAFE_componentWillMount
orUNSAFE_componentWillReceiveProps
. Detailed guide.useEffect
logic that assumed thatuseEffect(() => () => teardown(), [])
theteardown()
is only called once, and on unmount. Get a refresher on how useEffect works to make it easier to find and resolve these bugs.useEffect
,useMemo
,useCallback
and such either because they were suppressed in the linter due to// eslint-disable
or custom hooks and layers of abstractions made the linter unable to detect them.@types/react
until you have the bandwidth to fix the problems that the stricter typings uncover in your code.@sanity/ui
If you have a dependency on
@sanity/ui
and use it in your project make sure to bump it tov1
as it's upgraded to support the new concurrent renderer.Other changes
renderStudio
now returns a function for unmounting it, to make it easier to use in other libraries such asvue
,svelte
,solid
,angular
,jqueryui
,mootools
, whatever floats your boat. How about as a Web Component? ⛵See Codesandbox with example using Sanity Studio v3 in a web component.
React Strict Mode
You can opt-in to React's Strict Mode checks for your custom studio components in these ways:
reactStrictMode: true
to yoursanity.cli.ts
file..env.development
file and addSANITY_STUDIO_REACT_STRICT_MODE=true
to it.SANITY_STUDIO_REACT_STRICT_MODE=true sanity start
We strongly suggest you opt-in to better prepare your custom studio for the future of React. This only affects development mode, production mode or
sanity build
is unaffected by this setting.Schema
namespace removedThe
Schema
namespace has been removed. The same types can now be accessed as regular imports from thesanity
package.With this change it is now be possible to augment definition interfaces using declaration merging. This allows us to improve typesafety and intellisense in
defineType
schema helpers for plugins moving forward.See TSDoc on
defineType
for examples on this.Support for v2 theming
Improved search 🕵️
NOTE: Documents listed in search results will no longer resolve custom components for block content and array views
Slug functions context
Slug options
source
andslugify
are now passed a context parameter as the last argument. It containsgetClient
,schema
andcurrentUser
.🐛 Notable bugfixes
font-family
, and will no longer useserif
in cases where you don't use<Text>
from@sanity/ui
.📓 Full changelog
@sanity/pkg-utils
get-it
@types/babel__traverse
dependencyexports-check
action@babel/traverse
ToolMenu
toStudioToolMenu
, update API and add test id:sNavbar
toStudioNavbar
+ implementLogo
andToolMenu
fromstudio.components
StudioLogo
componentToolMenu
fromstudio.components
inNavDrawer
Navbar
fromstudio.components
inStudioLayout
Layout
fromcomponents.studio
inStudio
CollapseMenu
to enable adding test idToolMenu
NavbarStory
logo
from config typepreserveInstance
option on custom user panesurlParams
on custom user panes@sanity/pkg-utils
type-check
andverify_format
actionscheck:format
scripttest
actiontypescript
@sanity/util/fs
StudioFormBuilderProvider
and related (#3675)18
(#3612)@sanity/pkg-utils
etc/*.json
filessrc/
NodePresence
since it's a copy ofFormFieldPresence
react-track-elements
exports
directoryrouter
to separate exportRoute*
prefixsanity/router
importsanity/_unstable
intosanity
hookCollection
tosanity
ResourceCacheProviderProps
interfacedatastores
tostore/_legacy
sanity/form
intosanity
PreviewCard
componentIntentButton
prop typesPreviewCard
FileInput
toBaseFileInput
ImageInput
toBaseImageInput
sanity
to depcheck ignore listFormInput
to components directorychangeIndicators
out ofcomponents
components
which causes test failure@microsoft/api-extractor
buildetc/*.json
filesPatchOperations
interfacemerge
property toPatchOperations
NodeValidation => FormNodeValidation
FormFieldValidation => FormNodePresence
ref
propreactStrictMode
option (#3721)exclude
from tsconfigrenderDefault
schemaType
fromRenderPreviewCallback
type (added toPreviewProps
)StudioNavbar
NavDrawer
StudioLayout
Studio
FormProvider
renderDefault
from componentsrenderItem
toArrayInput
renderItem
toArrayOfPrimitivesInput
SanityPreview
to work with the components APIrenderDefault
to form input testssanity.config
FormBuilder
test@sanity/pkg-utils
dev
projects__DEV__
globaldist
directoryesbuild-register
esbuild-register
in workers (dev only)esbuild-register
esbuild-register
in dev-modebuildLegacyTheme()
function to enable v2 => v3 porting@sanity/ui
to v1.0.0-beta.29Popover
inTimelineMenu
@sanity/vision
includesreact
in bundledisconnect
method to mocked resize observerrenderDefault
in schema when resolving default form componentconstrainSize
propertyMenuButton
inImageActionsMenu
ImageInput
changesOpen
touseFormState
in order to enable disabling of group tabsplacement
on popover inPaneContextMenuButton
PopoverEditDialog
uiThis discussion was created from the release v3.0.0-dev-preview.22.
Beta Was this translation helpful? Give feedback.
All reactions