You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analyzing the error, I found that it occurs because the useSelector call occurs inside a useMemo, which is not recommended. The useMemo in question is this one:
The option I see would be to get the user in the PersistentSlashMenu component itself, and pass it to the restricted function. Would that be acceptable?
The option I see would be to get the user in the PersistentSlashMenu component itself, and pass it to the restricted function. Would that be acceptable?
@wesleybl That sounds like a pretty good solution to me. It's backwards compatible with existing implementations of restricted and sounds generally useful.
Describe the bug
I'm trying to make only a user with a Manager role add a certain block. I tried to restrict the block with the
restricted
function:https://6.docs.plone.org/volto/development/how-to-restrict-blocks.html
To get the user I used the
userSelector
inside therestricted
function. So when I click on a Text block when editing content, I get the error:Analyzing the error, I found that it occurs because the
useSelector
call occurs inside auseMemo
, which is not recommended. TheuseMemo
in question is this one:volto/packages/volto-slate/src/blocks/Text/SlashMenu.jsx
Line 119 in 0edcd80
And the call to the
restricted
function, which callsuseSelector
occurs here:volto/packages/volto-slate/src/blocks/Text/SlashMenu.jsx
Line 125 in 0edcd80
I believe it is not a good idea to remove
useMemo
. So what can be done? Is there any other way to restrict adding a block only to Manager?This is related to #5137
To Reproduce
Steps to reproduce the behavior:
https://github.com/plone/volto/blob/main/packages/volto/src/config/Blocks.jsx
import
useSelector
:restricted
in the HTML block:volto/packages/volto/src/config/Blocks.jsx
Line 386 in a496558
to:
Expected behavior
There should be no error when clicking on a Text block.
Software (please complete the following information):
Volto 18.0.0-alpha.42
Plone 6.0.11
plone.restapi 9.7.0
CMF 3.5
Zope 5.9
Python 3.11.9 (main, May 14 2024, 08:32:26) [GCC 10.2.1 20210110]
PIL 9.5.0 (Pillow)
The text was updated successfully, but these errors were encountered: