Skip to content

feat(ContextMenu): Introduce new API for imperative rendering #7391

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

Merged
merged 2 commits into from
Mar 27, 2025

Conversation

jscheiny
Copy link
Contributor

Changes proposed in this pull request:

This PR introduces a new rendering API for the showContextMenu and hideContextMenu options and deprecates the old API. The old API will be dropped in Blueprint 6.

Previously these functions would allow users to pass in an object with domRenderer and domUnmounter options which were implemented via ReactDOM.render and ReactDOM.unmountComponentAtNode respectively. This API does not work for React 18 which requires tracking a root node between the render and unmount stages. To allow for this, the new API instead allows passing a single render function which should return a function that unmounts the rendered node.

The default implementation still uses React 16 compatible defaults as before. In Blueprint 6 we will be making a few breaks here:

  1. Remove the DOMMountOptions<T> type from the options prop of showContextMenu
  2. Remove the options parameter of hideContextMenu
  3. Change the default implementation of the render method to use React 18 compatible methods. It will look something like:
const defaultRenderer: ShowContextMenuDOMRenderer = (element, container) => {
    const root = ReactDOMClient.createRoot(container);
    root.render(element);
    return () => root.unmount();
}

* A function render the React component onto a newly created DOM element. This should return a function which
* unmounts the rendered element from the DOM.
*/
render: ShowContextMenuDOMRenderer;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is required at the moment to make this type distinguishable from DOMMountOptions<T>. In BP6 this will be optional.

@svc-palantir-github
Copy link

feat(ContextMenu): Introduce new API for imperative rendering

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@jscheiny jscheiny marked this pull request as ready for review March 24, 2025 14:49
@svc-palantir-github
Copy link

Docs changes

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@jscheiny jscheiny merged commit 3ad9db1 into develop Mar 27, 2025
14 checks passed
@jscheiny jscheiny deleted the js/context-menu-new-render-api branch March 27, 2025 19:25
jscheiny added a commit that referenced this pull request Mar 27, 2025
Co-authored-by: Greg Douglas <gdouglas@palantir.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants