Aratramba/sanity-plugin-media-library

Using as asset source causes desk tool to crash

koriner opened this issue · 7 comments

I have the media library plugin installed and it all appears to work - but as soon as I add it as an asset source as described in your docs, it causes the desk tool to crash with an error Cannot read property 'displayName' of undefined

Here is the stack trace Sanity is showing in the UI

Stack trace:

TypeError: Cannot read property 'displayName' of undefined
    at withDocument (/static/js/app.bundle.js:68107:86)
    at http://localhost:3333/static/js/app.bundle.js:263471:42
    at Array.map (<anonymous>)
    at http://localhost:3333/static/js/app.bundle.js:263467:93
    at mountMemo (/static/js/vendor.bundle.js:18584:19)
    at Object.useMemo (/static/js/vendor.bundle.js:18880:16)
    at useMemo (/static/js/vendor.bundle.js:2327:21)
    at Object.wrappedHook [as useMemo] (/static/js/app.bundle.js:317949:14)
    at SanityImageInput (/static/js/app.bundle.js:263467:37)
    at renderWithHooks (/static/js/vendor.bundle.js:17945:18)

Component stack:

in ForwardRef(SanityImageInput) (created by FormBuilderInputInner)
    in ChangeIndicatorProvider (created by FormBuilderInputInner)
    in div (created by FormBuilderInputInner)
    in FormBuilderInputInner (created by FormBuilderInput)
    in FormBuilderInput (created by Field)
    in div (created by Field)
    in Field (created by ObjectInput)
    in div (created by ObjectInput)
    in div (created by ObjectInput)
    in ObjectInput (created by FormBuilderInputInner)
    in ChangeIndicatorProvider (created by FormBuilderInputInner)
    in div (created by FormBuilderInputInner)
    in FormBuilderInputInner (created by FormBuilderInput)
    in FormBuilderInput (created by SanityFormBuilder)
    in FormBuilderContext (created by SanityFormBuilderContext)
    in SanityFormBuilderContext (created by SanityFormBuilder)
    in SanityFormBuilder (created by EditForm)
    in form (created by EditForm)
    in EditForm (created by FormView)
    in div (created by ForwardRef(RegionsWithIntersections))
    in div (created by ForwardRef(RegionsWithIntersections))
    in ForwardRef(RegionsWithIntersections) (created by StickyOverlay)
    in StickyOverlay (created by OverlayEnabled)
    in Tracker (created by OverlayEnabled)
    in OverlayEnabled (created by FormView)
    in div (created by FormView)
    in FormView (created by DocumentPanel)
    in div (created by ForwardRef(ScrollContainer))
    in ForwardRef(ScrollContainer) (created by DocumentPanel)
    in div (created by DocumentPanel)
    in BoundaryElementProvider (created by DocumentPanel)
    in PortalProvider (created by DocumentPanel)
    in div (created by styled.div)
    in styled.div (created by Box)
    in Box (created by Styled(Box))
    in Styled(Box) (created by Card)
    in Ge (created by ThemeProvider)
    in ThemeProvider (created by ThemeColorProvider)
    in ThemeColorProvider (created by Card)
    in Card (created by DocumentPanel)
    in DocumentPanel (created by DocumentPane)
    in div (created by DocumentPane)
    in div (created by ForwardRef(ScrollContainer))
    in ForwardRef(ScrollContainer) (created by EnabledChangeConnectorRoot)
    in Tracker (created by EnabledChangeConnectorRoot)
    in EnabledChangeConnectorRoot (created by DocumentPane)
    in DialogProvider (created by DocumentPane)
    in div (created by KeyboardShortcutResponder)
    in KeyboardShortcutResponder (created by GetHookCollectionState)
    in GetHookCollectionState (created by RenderActionCollectionState)
    in RenderActionCollectionState (created by DocumentActionShortcuts)
    in DocumentActionShortcuts (created by DocumentPane)
    in LayerProvider (created by LegacyLayerProvider)
    in LegacyLayerProvider (created by DocumentPane)
    in DocumentPane (created by DocumentPaneProvider)
    in DocumentHistoryProvider (created by DocumentPaneProvider)
    in DocumentPaneProvider
    in StreamingComponent
    in StreamingComponent (created by Context.Consumer)
    in WithInitialValueWrapper (created by DeskToolPane)
    in DeskToolPane (created by DeskToolPanes)
    in SplitPaneWrapper (created by DeskToolPanes)
    in div (created by Pane)
    in Pane (created by SplitPane)
    in div (created by SplitPane)
    in SplitPane (created by PanesSplitController)
    in div (created by PanesSplitController)
    in div (created by Pane)
    in Pane (created by SplitPane)
    in div (created by SplitPane)
    in SplitPane (created by PanesSplitController)
    in div (created by PanesSplitController)
    in div (created by Pane)
    in Pane (created by SplitPane)
    in div (created by SplitPane)
    in SplitPane (created by PanesSplitController)
    in div (created by PanesSplitController)
    in PanesSplitController (created by DeskToolPanes)
    in PortalProvider (created by DeskToolPanes)
    in div (created by DeskToolPanes)
    in DeskToolPanes (created by DeskTool)
    in DeskTool (created by withRouter(DeskTool))
    in withRouter(DeskTool) (created by DeskToolPaneStateSyncer)
    in DeskToolPaneStateSyncer (created by DeskTool)
    in DeskToolFeaturesProvider (created by DeskTool)
    in DeskTool (created by RenderTool)
    in RenderTool (created by SchemaErrorReporter)
    in RouteScope (created by SchemaErrorReporter)
    in div (created by SchemaErrorReporter)
    in div (created by SchemaErrorReporter)
    in div (created by SchemaErrorReporter)
    in SchemaErrorReporter (created by DefaultLayout)
    in DefaultLayout (created by withRouter(DefaultLayout))
    in withRouter(DefaultLayout) (created by DefaultLayoutRoot)
    in RouterProvider (created by DefaultLayoutRoot)
    in LoginWrapper (created by DefaultLayoutRoot)
    in DefaultLayoutRoot (created by AppProvider)
    in div (created by styled.div)
    in styled.div (created by Box)
    in Box (created by Styled(Box))
    in Styled(Box) (created by Card)
    in Ge (created by ThemeProvider)
    in ThemeProvider (created by ThemeColorProvider)
    in ThemeColorProvider (created by Card)
    in Card (created by Styled(Card))
    in Styled(Card) (created by AppProvider)
    in SnackbarProvider (created by AppProvider)
    in ToastProvider (created by AppProvider)
    in LayerProvider (created by AppProvider)
    in PortalProvider (created by AppProvider)
    in UserColorManagerProvider (created by AppProvider)
    in AppProvider (created by SanityRoot)
    in Ge (created by ThemeProvider)
    in ThemeProvider (created by SanityRoot)
    in ZIndexProvider (created by SanityRoot)
    in SanityRoot
    in AppContainer

This error doesn't seem to be directly related to this plugin. What Sanity versions are you on (sanity versions)? And are you on the latest version of this plugin (1.0.7)?

Hmm it's weird because as soon as I comment out the part bit in sanity.json which specifies the asset source, the error goes away.

Sanity versions:

@sanity/cli             2.10.0 (up to date)
@sanity/base            2.10.2 (up to date)
@sanity/cli             2.10.0 (up to date)
@sanity/components       2.2.6 (up to date)
@sanity/core            2.10.2 (up to date)
@sanity/dashboard        2.7.0 (up to date)
@sanity/default-layout  2.10.2 (up to date)
@sanity/default-login    2.8.0 (up to date)
@sanity/desk-tool       2.10.2 (latest: 2.10.4)
@sanity/studio-hints     2.7.0 (up to date)
@sanity/types           2.10.0 (up to date)
@sanity/vision          2.10.0 (up to date)

And: "sanity-plugin-media-library": "^1.0.7",

could you share your sanity.json?

@Aratramba sure - it looks like this (when I include the reference to the asset source file)

{
  "root": true,
  "project": {
    "name": "..."
  },
  "api": {
    "projectId": "...",
    "dataset": "production"
  },
  "plugins": [
    "@sanity/base",
    "@sanity/components",
    "@sanity/default-layout",
    "@sanity/default-login",
    "@sanity/desk-tool",
    "@sanity/dashboard",
    "media-library"
  ],
  "env": {
    "development": {
      "plugins": ["@sanity/vision"]
    }
  },
  "parts": [
    {
      "name": "part:@sanity/base/schema",
      "path": "./schemas/schema"
    },
    {
      "name": "part:@sanity/desk-tool/structure",
      "path": "./src/structure/contentMenuStructure.ts"
    },
    {
      "name": "part:@sanity/base/new-document-structure",
      "path": "./src/structure/newDocumentStructure.ts"
    },
    {
      "implements": "part:@sanity/form-builder/input/image/asset-source",
      "path": "./src/assetSource/index.js"
    }
  ]
}

I have the same issue. I just installed this plugin and added as asset source and it crashes with the same error. I have the latest Sanity versions.

I also have the same issue with the latest Sanity versions.

Edit:
This fixed it for me:

In sanity.json change the line:
"implements": "part:@sanity/form-builder/input/image/asset-source",
to
"implements": "part:@sanity/form-builder/input/image/asset-sources",

Lovely! Works for me too, thanks @samesamestudio.