Skip to content

feat: allow slot prop vars as components #13573

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 6 commits into
base: main
Choose a base branch
from

Conversation

Fuzzyma
Copy link

@Fuzzyma Fuzzyma commented Jul 5, 2025

I had a shot about implementing the issue I raised in #8553.

Since I just look into the identifiers I feel like there must be some implications that I cant see yet. But the proof of concept works.

Happy for any feedback

Summary by CodeRabbit

  • New Features

    • Improved handling of component resolution within scoped slot bindings, ensuring components referenced via slot props are not incorrectly resolved as components.
  • Bug Fixes

    • Prevented unintended resolution of components when accessed through slot prop bindings.
  • Tests

    • Added new test cases to verify correct behavior for components referenced via scoped slot bindings.
  • Chores

    • Extended configuration options to support external identifier tracking for enhanced flexibility in transform and code generation contexts.

Copy link

coderabbitai bot commented Jul 5, 2025

Walkthrough

The changes introduce enhanced handling of component resolution within slot scope bindings in the compiler core. New test cases verify that components referenced via slot props are not resolved as normal components. The codebase is updated to support passing and checking an identifiers map for slot scope awareness, and internal logic is adjusted accordingly.

Changes

File(s) Change Summary
packages/compiler-core/tests/transforms/transformElement.spec.ts Added two test cases verifying components referenced via scoped slot bindings are not resolved as components.
packages/compiler-core/src/codegen.ts Updated CodegenContext type to omit the identifiers property from inherited options.
packages/compiler-core/src/options.ts Added optional identifiers property to SharedTransformCodegenOptions interface.
packages/compiler-core/src/transform.ts Allowed passing a custom identifiers map to createTransformContext and assigned it to the context object.
packages/compiler-core/src/transforms/transformElement.ts Modified resolveComponentType to check context.identifiers for slot prop-resolved components.

Sequence Diagram(s)

sequenceDiagram
  participant Compiler as Compiler
  participant TransformContext as TransformContext
  participant Codegen as Codegen

  Compiler->>TransformContext: createTransformContext(options, identifiers)
  Note right of TransformContext: identifiers map is set from options or default
  Compiler->>TransformContext: resolveComponentType(tag)
  alt tag in slot scope (identifiers)
    TransformContext->>TransformContext: Check identifiers for tag
    TransformContext-->>Compiler: Treat as slot prop, do not resolve as component
  else tag is normal component
    TransformContext->>TransformContext: Standard resolution logic
    TransformContext-->>Compiler: Resolve as component
  end
  Compiler->>Codegen: Generate code with context
Loading

Poem

In the warren of slots and tags we hop,
New tests ensure our checks don’t stop.
With identifiers mapped, we leap with care—
Components in slots? We’re well aware!
The code now knows where bunnies hide,
In every scoped slot, we peek inside.
🐇✨

Warning

Review ran into problems

🔥 Problems

Check-run timed out after 90 seconds. Some checks/pipelines were still in progress when the timeout was reached. Consider increasing the reviews.tools.github-checks.timeout_ms value in your CodeRabbit configuration to allow more time for checks to complete.


📜 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 eb8be28 and 23ae755.

📒 Files selected for processing (1)
  • packages/compiler-core/__tests__/transforms/transformElement.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/compiler-core/tests/transforms/transformElement.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
✨ 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

netlify bot commented Jul 5, 2025

Deploy Preview for vue-sfc-playground failed. Why did it fail? →

Name Link
🔨 Latest commit 50f23f9
🔍 Latest deploy log https://app.netlify.com/projects/vue-sfc-playground/deploys/68698d0ea187660008e6f194

Copy link

netlify bot commented Jul 5, 2025

Deploy Preview for vue-next-template-explorer failed. Why did it fail? →

Name Link
🔨 Latest commit 50f23f9
🔍 Latest deploy log https://app.netlify.com/projects/vue-next-template-explorer/deploys/68698d0e89104a00086374aa

@Fuzzyma Fuzzyma marked this pull request as ready for review July 6, 2025 18:38
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/compiler-core/src/transforms/transformElement.ts (1)

388-391: Consider removing or documenting the commented-out code.

The commented-out code for slot scope bindings handling should either be removed if not needed, or documented with a TODO comment explaining the future implementation plan.

-  // const fromSlotScope = checkType(BindingTypes.SLOT_SCOPE)
-  // if (fromSlotScope) {
-  //   return fromSlotScope
-  // }
+  // TODO: Future implementation for slot scope bindings
+  // const fromSlotScope = checkType(BindingTypes.SLOT_SCOPE)
+  // if (fromSlotScope) {
+  //   return fromSlotScope
+  // }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eca0e1c and eb8be28.

📒 Files selected for processing (5)
  • packages/compiler-core/__tests__/transforms/transformElement.spec.ts (2 hunks)
  • packages/compiler-core/src/codegen.ts (1 hunks)
  • packages/compiler-core/src/options.ts (1 hunks)
  • packages/compiler-core/src/transform.ts (2 hunks)
  • packages/compiler-core/src/transforms/transformElement.ts (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/compiler-core/__tests__/transforms/transformElement.spec.ts (2)
packages/compiler-core/src/index.ts (1)
  • BindingTypes (11-11)
packages/compiler-core/src/runtimeHelpers.ts (1)
  • RESOLVE_COMPONENT (26-28)
packages/compiler-core/src/codegen.ts (1)
packages/compiler-core/src/options.ts (1)
  • CodegenOptions (307-349)
🔇 Additional comments (7)
packages/compiler-core/src/options.ts (1)

203-203: LGTM! Well-integrated interface extension.

The addition of the optional identifiers property follows the existing pattern and maintains backward compatibility. The type signature is consistent with identifier tracking used elsewhere in the codebase.

packages/compiler-core/src/codegen.ts (1)

123-126: LGTM! Proper type boundary maintenance.

Adding 'identifiers' to the omitted properties list is correct and maintains type consistency. This follows the established pattern of excluding transform-specific properties from the codegen context.

packages/compiler-core/src/transforms/transformElement.ts (2)

285-300: LGTM! Well-implemented slot prop component resolution.

The new step correctly checks for components from slot props using context.identifiers. The logic properly handles both direct tags and dot notation components, and is appropriately gated for non-browser builds.


302-302: LGTM! Proper step renumbering.

The comment numbering has been correctly updated to reflect the new step insertion.

Also applies to: 319-319, 333-333

packages/compiler-core/src/transform.ts (2)

146-146: LGTM! Well-designed parameter addition.

Adding the optional identifiers parameter with Object.create(null) as the default is a good design choice. It enables external control of identifier tracking while maintaining backward compatibility.


191-191: LGTM! Proper context assignment.

The identifiers assignment correctly integrates the parameter into the transform context.

packages/compiler-core/__tests__/transforms/transformElement.spec.ts (1)

124-141: Well-structured test for slot prop component resolution.

The test correctly verifies that components referenced via scoped slot bindings (e.g., {Foo}) are not resolved as regular components. The test expectations are appropriate:

  • No RESOLVE_COMPONENT helper injection
  • Component not added to components list
  • Root node tag remains as the parent component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant