-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(ssr): filter out transition-specific props to avoid invalid HTML attributes #13894
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
f32d148
92e31b0
2a13148
ba3ac8a
d65747a
ca7407e
81615a2
a324b4e
a64f7f3
9f665ff
bf98abe
5590203
2a477e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,63 @@ import { | |
| createCallExpression, | ||
| findProp, | ||
| } from '@vue/compiler-dom' | ||
| import { hasOwn } from '@vue/shared' | ||
| import { SSR_RENDER_ATTRS } from '../runtimeHelpers' | ||
| import { | ||
| type SSRTransformContext, | ||
| processChildren, | ||
| } from '../ssrCodegenTransform' | ||
| import { buildSSRProps } from './ssrTransformElement' | ||
|
|
||
| // Import transition props validators from the runtime | ||
| const TransitionPropsValidators = (() => { | ||
| // Re-create the TransitionPropsValidators structure that's used at runtime | ||
| // This mirrors the logic from @vue/runtime-dom/src/components/Transition.ts | ||
| const BaseTransitionPropsValidators = { | ||
| mode: String, | ||
| appear: Boolean, | ||
| persisted: Boolean, | ||
| onBeforeEnter: [Function, Array], | ||
| onEnter: [Function, Array], | ||
| onAfterEnter: [Function, Array], | ||
| onEnterCancelled: [Function, Array], | ||
| onBeforeLeave: [Function, Array], | ||
| onLeave: [Function, Array], | ||
| onAfterLeave: [Function, Array], | ||
| onLeaveCancelled: [Function, Array], | ||
| onBeforeAppear: [Function, Array], | ||
| onAppear: [Function, Array], | ||
| onAfterAppear: [Function, Array], | ||
| onAppearCancelled: [Function, Array], | ||
| } | ||
|
|
||
| const DOMTransitionPropsValidators = { | ||
| name: String, | ||
| type: String, | ||
| css: { type: Boolean, default: true }, | ||
| duration: [String, Number, Object], | ||
| enterFromClass: String, | ||
| enterActiveClass: String, | ||
| enterToClass: String, | ||
| appearFromClass: String, | ||
| appearActiveClass: String, | ||
| appearToClass: String, | ||
| leaveFromClass: String, | ||
| leaveActiveClass: String, | ||
| leaveToClass: String, | ||
| } | ||
|
|
||
| return { | ||
| ...BaseTransitionPropsValidators, | ||
| ...DOMTransitionPropsValidators, | ||
| } | ||
| })() | ||
|
|
||
| // Helper function to convert kebab-case to camelCase | ||
| function kebabToCamel(str: string): string { | ||
| return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase()) | ||
| } | ||
|
|
||
| const wipMap = new WeakMap<ComponentNode, WIPEntry>() | ||
|
|
||
| interface WIPEntry { | ||
|
|
@@ -32,7 +82,49 @@ export function ssrTransformTransitionGroup( | |
| return (): void => { | ||
| const tag = findProp(node, 'tag') | ||
| if (tag) { | ||
| const otherProps = node.props.filter(p => p !== tag) | ||
| // Filter out all transition-related private props when processing TransitionGroup attributes | ||
| const otherProps = node.props.filter(p => { | ||
| // Exclude tag (already handled separately) | ||
| if (p === tag) { | ||
| return false | ||
| } | ||
|
|
||
| // Exclude all transition-related attributes and TransitionGroup-specific attributes | ||
| // This logic mirrors the runtime TransitionGroup attribute filtering logic | ||
| if (p.type === NodeTypes.ATTRIBUTE) { | ||
| // Static attributes: check attribute name (supports kebab-case to camelCase conversion) | ||
| const propName = p.name | ||
| const camelCaseName = kebabToCamel(propName) | ||
| const shouldFilter = | ||
| hasOwn(TransitionPropsValidators, propName) || | ||
| hasOwn(TransitionPropsValidators, camelCaseName) || | ||
| propName === 'moveClass' || | ||
| propName === 'move-class' | ||
| return !shouldFilter | ||
| } else if (p.type === NodeTypes.DIRECTIVE && p.name === 'bind') { | ||
| // Dynamic attributes: check bound attribute name | ||
| if ( | ||
| p.arg && | ||
| p.arg.type === NodeTypes.SIMPLE_EXPRESSION && | ||
| p.arg.isStatic | ||
| ) { | ||
| const argName = p.arg.content | ||
| const camelCaseArgName = kebabToCamel(argName) | ||
| const shouldFilter = | ||
| hasOwn(TransitionPropsValidators, argName) || | ||
| hasOwn(TransitionPropsValidators, camelCaseArgName) || | ||
| argName === 'moveClass' || | ||
| argName === 'move-class' | ||
| return !shouldFilter | ||
| } else if (!p.arg) { | ||
|
||
| // v-bind without argument (e.g., v-bind="props") - filter out entirely | ||
| // since it may contain transition-specific props that should not be rendered | ||
| return false | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return true | ||
| }) | ||
| const { props, directives } = buildProps( | ||
| node, | ||
| context, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event handlers are not included in the SSR output, so this test is redundant.
see ssr output in Playground