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

Add prepareContainer option to mount function #59

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Dec 2, 2024

As discussed in slack, this PR adds a prepareContainer?: (container: HTMLElement) => void option to the mount function, which allows to customize the container when connect is true.

@acelaya
Copy link
Contributor Author

acelaya commented Dec 2, 2024

Since we have already agreed on this API, I'll just go ahead and merge it.

@acelaya acelaya merged commit ad5e486 into main Dec 2, 2024
2 checks passed

/**
* When `connected` is true, allows to customize the container to which the
* wrapper is connected to.
Copy link
Member

Choose a reason for hiding this comment

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

I would phrase this as "allows customizing the DOM container in which the component is mounted".

let wrapper;
if (connected) {
const container = document.createElement('div');
container.setAttribute('data-enzyme-container', '');
containers.push(container);

prepareContainer?.(container);
Copy link
Member

Choose a reason for hiding this comment

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

It is possible we might encounter use cases in future where the callback needs the container to be connected (ie. in the body) when called. This would be necessary to resolved computed styles for example. I haven't seen any existing use cases where this is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now I added the call before appending the container to the body, because that was the approach in all places where we were setting styles.

But yeah, it's possible we need to do it the other way around in the future.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I noted a hazard with the ordering of operations we might encounter in future and suggested some wording tweaks to the comment.

@acelaya acelaya deleted the mount-prepare-container branch December 2, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants