-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
feat(compiler-core): error if portal doesn't have target #384
base: main
Are you sure you want to change the base?
Conversation
Even though an old PR, this still seems like a good addition. Before getting back to this and solving merge conflicts though, we should fix some of the existing bugs first (see |
@@ -125,6 +125,13 @@ export const transformElement: NodeTransform = (node, context) => { | |||
args.push(propsBuildResult.props) | |||
} | |||
} | |||
|
|||
if (node.tagType === ElementTypes.PORTAL && !findProp(node, 'target')) { |
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.
I know this is an old PR, but given it's still open...
Should this maybe take account of v-bind="obj"
too? The target could be passed in obj
rather than as a separate prop.
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.
Agreed with @skirtles-code. We also need to consider v-bind="obj"
, which cannot be done at compile phase. So we do it at runtime. see
core/packages/runtime-core/src/components/Teleport.ts
Lines 56 to 63 in 928af5f
const target = select(targetSelector) | |
if (__DEV__ && !target && !isTeleportDisabled(props)) { | |
warn( | |
`Failed to locate Teleport target with selector "${targetSelector}". ` + | |
`Note the target element must exist before the component is mounted - ` + | |
`i.e. the target cannot be rendered by the component itself, and ` + | |
`ideally should be outside of the entire Vue component tree.`, | |
) |
I think this PR can be closed. @skirtles-code WDYT?
This will help people see their mistakes, erroring compilation of code failing in runtime. E.g. if user uses Vetur, they'll see mistakes in dev-time, not in runtime.
Examples of valid code:
Examples of erroring code: