Skip to content

fix(transition): fix KeepAlive with transition out-in mode behavior in production #12468

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 8 commits into from
May 13, 2025

Conversation

yangxiuxiu1115
Copy link
Contributor

@yangxiuxiu1115 yangxiuxiu1115 commented Nov 25, 2024

fix #12465

Summary by CodeRabbit

  • Tests
    • Added a new test to verify "out-in" transition mode with KeepAlive and fallthrough attributes in production mode.
  • Bug Fixes
    • Improved handling of component subtrees in transitions to ensure consistent behavior across development and production environments.

Copy link

github-actions bot commented Nov 25, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+42 B) 38.2 kB (+11 B) 34.4 kB (-14 B)
vue.global.prod.js 159 kB (+42 B) 58.4 kB (+11 B) 51.9 kB (+34 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.6 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.3 kB 22.8 kB 20.8 kB
overall 68.6 kB (+42 B) 26.4 kB (+11 B) 24.1 kB (+49 B)

Copy link

pkg-pr-new bot commented Nov 25, 2024

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@12468

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@12468

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@12468

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@12468

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@12468

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@12468

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@12468

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@12468

@vue/shared

npm i https://pkg.pr.new/@vue/shared@12468

vue

npm i https://pkg.pr.new/vue@12468

@vue/compat

npm i https://pkg.pr.new/@vue/compat@12468

commit: 237ff5f

@skirtles-code
Copy link
Contributor

That branch of the code has a comment on it:

  // #7121 ensure get the child component subtree in case
  // it's been replaced during HMR

It would appear that the author of that section only intended for it to be used during HMR. If it's going to be used in production then that comment needs updating.

Did you investigate why that code was added just for HMR?


More generally, could you also please include more details in your PR descriptions? Presumably you spent a while debugging this before deciding what the appropriate fix should be. What did you find? Why do you think this is the correct fix? If you don't provide that information in the description then anyone reviewing the change is going to need to go through that debugging and exploration process all over again.

Reviewing a PR, even a small one like this, can take a reviewer several hours. We don't just need to check that the fix works, we need to assess whether it's actually the best fix for the underlying problem. Providing a brief explanation in the PR description of what you think the underlying problem is and why you think it's the right fix can save us a huge amount of time. It can also be really valuable months down the line when someone wants to understand why a particular change was made.

Thanks.

@yangxiuxiu1115 yangxiuxiu1115 marked this pull request as draft November 26, 2024 02:34
@yangxiuxiu1115
Copy link
Contributor Author

yangxiuxiu1115 commented Nov 26, 2024

Thank you very much for your reply, honestly I'm not very good at English, most of the time I rely on translation software, how to use English accurately might be really difficult for me, but that's my problem.

Return to PR, To be honest I did overlook that code comment you mentioned. But this is just my simple attempt, he may not be correct

debugging the issue is really tricky, one thing to note about this issue is that when class=“test” is removed from the transition, everything goes back to normal. This is due to the indirect effect of fallthroughAttrs, which clones a new vnode when it exists, which causes vnode.component.subTree and vnode.children[0] to get completely different values.

Then look at the difference between DEV and PROD, when there are fallthroughAttrs then vnode.component.subTree is the correct child vnode, so everything works fine in the DEV environment too!

NOTE:
The overall debugging idea can be started from the vnode, you can simply debug the number of updates on DEV and PROD, you can find that there is a missing update on PROD, and the last update is triggered by the afterLeave on the transition.

@yangxiuxiu1115 yangxiuxiu1115 marked this pull request as ready for review November 26, 2024 04:07
@edison1105 edison1105 requested a review from Copilot November 27, 2024 01:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.

@edison1105
Copy link
Member

I think this PR should be correct. It is similar to #7121 where the root node has switched. We should always apply the transition to their component.subTree without distinguishing between DEV and PROD if the component is already mounted. The comments mentioned above need to be updated.

This needs a test case by the way.

@edison1105 edison1105 added need test The PR has missing test cases. scope: transition 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Nov 27, 2024
@edison1105 edison1105 added ready to merge The PR is ready to be merged. and removed need test The PR has missing test cases. labels Nov 27, 2024
@edison1105 edison1105 changed the title fix(transition): align the different transition behaviors of dev and prod fix(transition): fix KeepAlive with transition out-in mode behavior in production Nov 27, 2024
@vuejs vuejs deleted a comment from edison1105 Apr 10, 2025
Copy link

coderabbitai bot commented May 13, 2025

Walkthrough

A test was added to verify that the BaseTransition component with KeepAlive and fallthrough attributes behaves identically in both development and production modes. Additionally, the getInnerChild function in BaseTransition.ts was updated to ensure consistent handling of component subtrees, removing a development-only condition and updating related comments.

Changes

File(s) Change Summary
packages/runtime-core/tests/components/BaseTransition.spec.ts Added a test for "out-in" mode with KeepAlive and fallthrough attributes in production mode.
packages/runtime-core/src/components/BaseTransition.ts Modified getInnerChild to remove the __DEV__ guard, ensuring consistent behavior between dev and prod.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant BaseTransition
    participant KeepAlive
    participant ComponentA
    participant ComponentB

    TestRunner->>BaseTransition: Mount with KeepAlive and fallthrough attrs (prod mode)
    BaseTransition->>KeepAlive: Render branch A (ComponentA)
    KeepAlive->>ComponentA: Render with class attribute
    TestRunner->>BaseTransition: Toggle to branch B
    BaseTransition->>ComponentA: Trigger leave hooks
    Note right of BaseTransition: onBeforeLeave/onLeave called
    BaseTransition->>KeepAlive: After leave, render branch B (ComponentB)
    KeepAlive->>ComponentB: Render with class attribute
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure consistent BaseTransition + KeepAlive + fallthrough attribute behavior in dev/prod (#12465)
Remove dev-only logic in getInnerChild for consistent subtree handling (#12465)

Poem

A rabbit hopped through code so bright,
Ensuring transitions worked just right.
Dev and prod now act the same,
No more bugs to cause us shame!
With tests in place, we leap with glee—
Consistency for all to see! 🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 258f78b and 237ff5f.

📒 Files selected for processing (2)
  • packages/runtime-core/__tests__/components/BaseTransition.spec.ts (1 hunks)
  • packages/runtime-core/src/components/BaseTransition.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / e2e-test
🔇 Additional comments (2)
packages/runtime-core/src/components/BaseTransition.ts (1)

504-505: Ensure consistent component subtree handling in all environments

This change fixes the inconsistency between development and production builds by always using the component's subtree if the component exists, regardless of build environment. The updated comment correctly documents both issue references (#7121, #12465) and clarifies the purpose of this code.

packages/runtime-core/__tests__/components/BaseTransition.spec.ts (1)

1202-1247: Great test coverage for the production mode fix

This test correctly verifies the fix by:

  1. Temporarily setting __DEV__ = false to simulate production environment
  2. Testing the specific scenario with KeepAlive, "out-in" transition mode, and fallthrough attributes
  3. Verifying that the DOM elements maintain the correct class attributes during transitions
  4. Confirming the expected hook call sequence

The test thoroughly validates that the fix in BaseTransition.ts works as expected in production builds.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented May 13, 2025

📝 Ran ecosystem CI: Open

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

@vuejs vuejs deleted a comment from edison1105 May 13, 2025
@edison1105 edison1105 merged commit 343c891 into vuejs:main May 13, 2025
14 checks passed
@yangxiuxiu1115 yangxiuxiu1115 deleted the fix/prod-transition branch May 14, 2025 13:03
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. ready to merge The PR is ready to be merged. scope: transition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transition got different behavior in dev & prod mode
5 participants