Skip to content

fix(runtime-dom): inconsistent behaviour on nested transition groups #8803

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

daniser
Copy link

@daniser daniser commented Jul 18, 2023

fixes #1531
close #5385

Summary by CodeRabbit

  • Refactor
    • Improved how element positions are calculated for transitions, now measuring positions relative to parent elements for smoother animations. No changes to user-facing features or controls.

@skirtles-code
Copy link
Contributor

For anyone trying to review this, here's the original reproduction, converted to a Playground:

Here's the same example but running on this PR:

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

Would you be able to merge in main, to resolve the conflicts and get the latest ESLint rules?

@daniser
Copy link
Author

daniser commented Jun 24, 2024

@skirtles-code Done!

Copy link

github-actions bot commented Aug 20, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (+146 B) 38 kB (+45 B) 34.2 kB (+17 B)
vue.global.prod.js 159 kB (+146 B) 57.9 kB (+38 B) 51.5 kB (+22 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.9 kB 18.3 kB 16.7 kB
createApp 55 kB 21.3 kB 19.4 kB
createSSRApp 59 kB 23 kB 21 kB
defineCustomElement 59.8 kB 22.8 kB 20.8 kB
overall 68.7 kB 26.3 kB 24 kB

@edison1105
Copy link
Member

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Aug 20, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@8803

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@8803

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@8803

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@8803

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@8803

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@8803

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@8803

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@8803

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@8803

vue

pnpm add https://pkg.pr.new/vue@8803

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@8803

commit: 29a1647

@vue-bot
Copy link
Contributor

vue-bot commented Aug 20, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt failure success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105 edison1105 added 🐞 bug Something isn't working scope: transition ready for review This PR requires more reviews labels Aug 20, 2024
@daniser
Copy link
Author

daniser commented Sep 13, 2024

Any estimate on when it'll be merged? It's been over a year.

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Nov 4, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools success success
nuxt success success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue failure failure
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105
Copy link
Member

/ecosystem-ci run vite-plugin-vue

@vue-bot
Copy link
Contributor

vue-bot commented Nov 4, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
vite-plugin-vue success failure

@edison1105 edison1105 added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Mar 19, 2025
Copy link

coderabbitai bot commented Jun 11, 2025

Walkthrough

The change introduces a helper function to compute an element's position relative to its parent, replacing the previous use of absolute bounding rectangles. The position-tracking logic in the TransitionGroup component is updated to use this relative positioning, and a new Position interface is added for type safety. No other logic or control flow is changed.

Changes

File(s) Change Summary
packages/runtime-dom/src/components/TransitionGroup.ts Replaced use of getBoundingClientRect() with new getRelativePosition() helper; introduced Position interface; updated position tracking logic to use relative positions.

Sequence Diagram(s)

sequenceDiagram
    participant TransitionGroup
    participant DOMElement
    participant ParentElement

    TransitionGroup->>DOMElement: getBoundingClientRect()
    TransitionGroup->>ParentElement: getBoundingClientRect()
    TransitionGroup->>TransitionGroup: getRelativePosition(el)
    Note right of TransitionGroup: Compute relative left/top
    TransitionGroup->>TransitionGroup: Store {left, top} in positionMap
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct relative positioning for nested transition groups (#1531, #5385)
Prevent unnecessary move animations in nested transition groups (#5385)
Ensure position tracking logic is updated for nested group scenarios (#1531)

Poem

In the garden where transitions bloom,
Rabbits hop and elements zoom.
With positions now relative, not absolute,
Animations glide—no need to dispute!
Nested groups now move just right,
Bugs hop away, out of sight.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/runtime-dom/src/components/TransitionGroup.ts (1)

153-155: Pure function call during render – just double-check perf

getRelativePosition is executed for every child on every render. It still triggers getBoundingClientRect, which forces a layout read twice per element (old/new). While this is inherited from the previous implementation, consider caching the first read inside the loop or switching to offsetLeft/offsetTop where possible to reduce layout thrashing in very large lists.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdffaf6 and b48c5a4.

📒 Files selected for processing (1)
  • packages/runtime-dom/src/components/TransitionGroup.ts (3 hunks)
🔇 Additional comments (2)
packages/runtime-dom/src/components/TransitionGroup.ts (2)

32-35: Small, well-scoped data structure – looks good

A minimal Position interface (only left/top) keeps the payload lean and avoids carrying useless properties that used to be present (width/height).


37-38: Correct use of WeakMap avoids leaks

Using VNode as the key and a WeakMap ensures the stored coordinates are garbage-collected when the VNode is discarded – thumbs-up.

Comment on lines +193 to +207
function getRelativePosition(el: Element): Position {
const elRect = el.getBoundingClientRect()
if (!el.parentElement) {
return {
left: elRect.left,
top: elRect.top,
}
}

const parentRect = el.parentElement.getBoundingClientRect()
return {
left: elRect.left - parentRect.left,
top: elRect.top - parentRect.top,
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

parentElement may be null – relative delta becomes wrong

getRelativePosition falls back to absolute viewport coords when el.parentElement is null (e.g. the parent is a DocumentFragment, a comment, or the node is temporarily detached).
If that happens between the “old” and “new” snapshots, dx/dy will be computed against mixed coordinate spaces → items jump instead of animating.

Proposed defensive tweak:

function getRelativePosition(el: Element): Position {
-  const elRect = el.getBoundingClientRect()
-  if (!el.parentElement) {
-    return {
-      left: elRect.left,
-      top: elRect.top,
-    }
-  }
-
-  const parentRect = el.parentElement.getBoundingClientRect()
+  const elRect = el.getBoundingClientRect()
+  const parent = el.parentElement as Element | null
+  if (!parent) {
+    // No element parent (e.g. DocumentFragment) — treat the container itself
+    // as the reference so both snapshots stay in the same coordinate space.
+    return { left: elRect.left, top: elRect.top }
+  }
+
+  const parentRect = parent.getBoundingClientRect()
   return {
     left: elRect.left - parentRect.left,
     top: elRect.top - parentRect.top,
   }
 }

This keeps both snapshots in the same space and avoids incorrect deltas.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/runtime-dom/src/components/TransitionGroup.ts around lines 193 to
207, the getRelativePosition function returns absolute viewport coordinates when
el.parentElement is null, causing inconsistent coordinate spaces and incorrect
delta calculations. To fix this, modify the function to always compute positions
relative to a consistent ancestor or coordinate space, such as the document or a
stable container, ensuring both old and new snapshots use the same reference
frame and preventing animation jumps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working ready for review This PR requires more reviews scope: transition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary move animation in nested <transition-group> inconsistent behaviour on nested transition groups
4 participants