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

Error if no block pattern has a category #28237

Closed
kraftner opened this issue Jan 15, 2021 · 5 comments
Closed

Error if no block pattern has a category #28237

kraftner opened this issue Jan 15, 2021 · 5 comments
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] Needs More Info Follow-up required in order to be actionable.

Comments

@kraftner
Copy link

Description

If no registered block patterns has a category the editor errors.

I haven't really dug deep into the code but I think this looks like assuming there always is a category:

const patternCategory = selectedCategory
? selectedCategory
: populatedCategories[ 0 ];

Step-by-step reproduction instructions

  1. Unregister all block patterns (either using remove_theme_support( 'core-block-patterns' );or unregister_block_pattern())
  2. Register a new pattern without a category since that is optional according to the docs
  3. Open the Patterns tab in the editor.
  4. Editor Error.

Expected behaviour

  1. No Error.
  2. The editor doesn't show the category select or shows it with only "Uncategorized"

Actual behaviour

Uncaught TypeError: patternCategory is undefined
    currentCategoryPatterns http://localhost:8080/wp-includes/js/dist/block-editor.js?ver=5f6a75cdc59f1a900e9d4bcfb43bddba:27781
    currentCategoryPatterns http://localhost:8080/wp-includes/js/dist/block-editor.js?ver=5f6a75cdc59f1a900e9d4bcfb43bddba:27780
    mountMemo http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:15577
    useMemo http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:15873
    useMemo http://localhost:8080/wp-includes/js/dist/vendor/react.js?ver=16.13.1:1607
    BlockPatternsCategory http://localhost:8080/wp-includes/js/dist/block-editor.js?ver=5f6a75cdc59f1a900e9d4bcfb43bddba:27779
    renderWithHooks http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:14938
    mountIndeterminateComponent http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:17617
    beginWork http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:18731
    callCallback http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:182
    invokeGuardedCallbackDev http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:231
    invokeGuardedCallback http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:286
    beginWork$1 http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:23338
    performUnitOfWork http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22292
    workLoopSync http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22265
    performSyncWorkOnRoot http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:21891
    flushSyncCallbackQueueImpl http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11224
    unstable_runWithPriority http://localhost:8080/wp-includes/js/dist/vendor/react.js?ver=16.13.1:2685
    runWithPriority$1 http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11174
    flushSyncCallbackQueueImpl http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11219
    flushSyncCallbackQueue http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11207
    discreteUpdates$1 http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22028
    discreteUpdates http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:803
    dispatchDiscreteEvent http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:4291
    addEventBubbleListener http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:4150
    trapEventForPluginEventSystem http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:4285
    trapBubbledEvent http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:4256
    legacyListenToTopLevelEvent http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:3765
    legacyListenToEvent http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:3724
    ensureListeningTo http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:5884
    setInitialDOMProperties http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:5951
    setInitialProperties http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:6149
    finalizeInitialChildren http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:7622
    completeWork http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:19113
    completeUnitOfWork http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22324
    performUnitOfWork http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22300
    workLoopSync http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:22265
    performSyncWorkOnRoot http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:21891
    flushSyncCallbackQueueImpl http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11224
    unstable_runWithPriority http://localhost:8080/wp-includes/js/dist/vendor/react.js?ver=16.13.1:2685
    runWithPriority$1 http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11174
    flushSyncCallbackQueueImpl http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11219
    flushSyncCallbackQueue http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:11207
    scheduleUpdateOnFiber http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:21334
    dispatchAction http://localhost:8080/wp-includes/js/dist/vendor/react-dom.js?ver=16.13.1:15795
    onStoreChange http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:3705
    unsubscribe http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:3721
    globalListener http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:2813
    globalListener http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:2812
    subscribe http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:2401
    dispatch http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:1208
    createMiddleware Redux
    promiseMiddleware http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:1914
    createResolversCacheMiddleware http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:1970
    dispatch http://localhost:8080/wp-includes/js/dist/data.js?ver=777f925bfe1a2aea2a86b7b9ae6aed25:1612
    Redux 32
block-editor.js:27781:7
The above error occurred in the <BlockPatternsCategory> component:
    in BlockPatternsCategory (created by BlockPatternsTabs)
    in BlockPatternsTabs (created by InserterMenu)
    in div (created by TabPanel)
    in div (created by TabPanel)
    in TabPanel (created by InserterTabs)
    in InserterTabs (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in InserterMenu (created by InserterLibrary)
    in InserterLibrary (created by Layout)
    in div (created by Layout)
    in div (created by Layout)
    in Unknown (created by FocusReturn)
    in div (created by FocusReturn)
    in FocusReturn (created by Context.Consumer)
    in WithFocusReturn(Component) (created by WithConstrainedTabbing(WithFocusReturn(Component)))
    in div (created by WithConstrainedTabbing(WithFocusReturn(Component)))
    in WithConstrainedTabbing(WithFocusReturn(Component)) (created by PopoverWrapper)
    in _class (created by WithFocusOutside(_class))
    in div (created by WithFocusOutside(_class))
    in WithFocusOutside(_class) (created by PopoverWrapper)
    in div (created by PopoverWrapper)
    in PopoverWrapper (created by Layout)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in InterfaceSkeleton (created by NavigateRegions(InterfaceSkeleton))
    in div (created by NavigateRegions(InterfaceSkeleton))
    in NavigateRegions(InterfaceSkeleton) (created by Layout)
    in div (created by FocusReturnProvider)
    in FocusReturnProvider (created by Layout)
    in Layout (created by Editor)
    in ErrorBoundary (created by Editor)
    in BlockEditorProvider
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(BlockEditorProvider) (created by EditorProvider)
    in BlockContextProvider (created by EditorProvider)
    in EntityProvider (created by EditorProvider)
    in EntityProvider (created by EditorProvider)
    in EditorProvider (created by WithDispatch(EditorProvider))
    in WithDispatch(EditorProvider)
    in Unknown (created by WithSelect(WithDispatch(EditorProvider)))
    in WithSelect(WithDispatch(EditorProvider))
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(WithSelect(WithDispatch(EditorProvider))) (created by Editor)
    in div (created by DropZoneProvider)
    in DropZoneProvider (created by Editor)
    in slot_fill_provider_SlotFillProvider (created by SlotFillProvider)
    in SlotFillProvider (created by Editor)
    in StrictMode (created by Editor)
    in Editor (created by WithDispatch(Editor))
    in WithDispatch(Editor)
    in Unknown (created by WithSelect(WithDispatch(Editor)))
    in WithSelect(WithDispatch(Editor))

React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary. react-dom.js:19662:15

Screenshots or screen recording (optional)

Code snippet (optional)

WordPress information

  • WordPress version: 5.6.0
  • Gutenberg version: Not installed
@skorasaurus
Copy link
Member

Hi,

Thanks for reporting. This appears to be a duplicate of #27249

Could you check if you still have this issue when you have the Gutenberg plugin installed?

@skorasaurus skorasaurus added [Status] Needs More Info Follow-up required in order to be actionable. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jan 15, 2021
@kraftner
Copy link
Author

After installing the Gutenberg plugin I now get the exact same error as in #27429.

Should this be fixed in Gutenberg?

@skorasaurus
Copy link
Member

@kraftner thanks for the update. This has has been fixed very recently in Gutenberg with #27970 and the fix will likely be included in Gutenberg 9.8.

Thanks again for reporting.

@kraftner
Copy link
Author

I'll keep an eye on this then and sorry for not finding the other issue. 😉 Thanks @skorasaurus!

@skorasaurus
Copy link
Member

no problem, thanks again for your informative report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] Needs More Info Follow-up required in order to be actionable.
Projects
None yet
Development

No branches or pull requests

2 participants