-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Actions do not have access to parent nodes anymore #4166
Comments
@tanhauhau Was there a reason in #4156 you switched attaching actions to be during creation rather than mounting? I don't think the docs explicitly say whether the element will be mounted in the DOM by the time the action is called, but it does seem like there are situations where it would be useful. |
The reason was to have event listeners and attaching actions in the same phase, so we can order them. |
I was just hit by this confusion while trying to apply a scroll top to an element on mount. The following example doesn't work because the action is called before the node is mounted. <script>
const scrollToCenter = node => {
node.scrollTop = 500;
};
</script>
<div use:scrollToCenter>
<slot></slot>
</div> The docs are misleading https://svelte.dev/docs#use_action // the node has been mounted in the DOM |
Fixed in 3.17.0 - https://svelte.dev/repl/b280b938304247a5ae891af8c62ce7d6?version=3.17.0 |
Describe the bug
I have an action that requires knowledge about parentNode of an element. A simplified version looks like this:
To Reproduce
Expected behavior
I expect that the action will be called after the node has been attached to the DOM. Because this is how it worked in the past versions.
Additional context
I am using this action to implement draggable element. It needs to know the parent node to properly compute positioning. Real code can be found here: https://github.com/just-boris/components-graph/blob/master/src/utils/drag.js#L2
I suspect that the issue was introduced by this PR: #4156
The text was updated successfully, but these errors were encountered: