-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
feat: implementing translations api #434
base: master
Are you sure you want to change the base?
Conversation
@gloaysa is attempting to deploy a commit to the dargo's projects Team on Vercel. A member of the Team first needs to authorize it. |
if (render) { | ||
return ( | ||
// [TODO] - take care about SSR | ||
const menuContent = render ? render({ ...renderProps, actions: blockTypes }) : <DefaultActionMenuRender {...renderProps} actions={blockTypes} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code conditionally skips parts of the component tree based on render, which changes the structure React expects, violating the Rules of Hooks; the fix ensures consistent structure by dynamically selecting content via a variable.
I hope is ok, had to tackle this issue on this PR since it was introducing a bug (I'm using the new useTranslate hook in the conditionally rendered children DefaultActionMenuRender).
@@ -95,11 +95,16 @@ const ActionMenuList = ({ items, render }: ActionMenuToolProps) => { | |||
duration: 100, | |||
}); | |||
|
|||
const blockTypes: ActionMenuToolItem[] = mapActionMenuItems(editor, items || Object.keys(editor.blocks)); | |||
const blockTypes = useMemo(() => mapActionMenuItems(editor, items || Object.keys(editor.blocks)), [editor, items]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not directly related to my feature, I'm just following the boy-scout rule.
I've noticed that this is recalculated on every render. If editor or items doesn’t change, this causes unnecessary re-renders.
|
||
const [selectedAction, setSelectedAction] = useState<ActionMenuToolItem>(blockTypes[0]); | ||
const [actions, setActions] = useState<ActionMenuToolItem[]>(blockTypes); | ||
|
||
useEffect(() => { | ||
setActions(blockTypes); | ||
setSelectedAction(blockTypes[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not directly related to my feature, I'm just following the boy-scout rule.
If loading actions dynamically, the list wasn't being updated. This change syncs the actions if the blockTypes change.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
#273
Type of change
Please tick the relevant option.
Checklist:
Screenshots:
Screen.Recording.2025-01-04.at.17.10.45.mov