Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Templates in subdirectories couldn't be referenced by path (e.g., @await PartialAsync("template/topNav")), and filename-only lookups conflicted when multiple templates shared the same name.

Changes

RazorRenderer.cs

  • Store templates with both relative path (template/topNav) and filename (topNav) keys
  • Add FindTemplate() with multi-strategy lookup: exact match, extension variants, normalized separators
  • Update RenderTemplateContent() and RenderContentAsync() to use new lookup

RazorTests.cs

  • Add tests for subdirectory resolution, backward compatibility, extension handling, path normalization

Usage

// All now work correctly:
@await PartialAsync("template/topNav")           // subdirectory path
@await PartialAsync("template/topNav.cshtml")    // with extension
@await PartialAsync("Footer")                    // root-level (backward compat)

Previously, only root-level filename lookups worked, and subdirectory templates with duplicate names would conflict.

Original prompt

This section details on the original issue you should resolve

<issue_title>Inconsistent Partial rendering behavior</issue_title>
<issue_description>User report:

so this is interesting. the docs say i can do this:

@await PartialAsync("topNav")

and i have a template/topNav.cshtml file, however, it wouldn’t build until i fully qualified it:

@await PartialAsync("template/topNav.cshtml")

and after that, instead of loading the topNav, it actually loaded the Default.cshtml, so i have two body contents here:

        @await PartialAsync("template/topNav.cshtml")

        @Raw(Model.Body)

if i remove that topNav template inclusion, i only get one body content.

Acceptance Criteria

  • paths should resolve relatively ... so if template/topNav.cshtml is being rendered from another template in that same template folder, it should correctly resolve.
  • The 2nd reported issue, of it rendering Default.cshtml instead of the requested topNav.cshtml is obviously incorrect.

First, confirm this behavior by compiling the project, creating a conceptual template, and modifying it as described. Second, fix the issues and add unit tests to match the correct behavior. And lastly, re-compile, boostrap a conceptual template, and re-try to confirm fixed behavior.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: joelmartinez <90380+joelmartinez@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inconsistent partial rendering behavior Fix template resolution to support subdirectory paths Nov 14, 2025
Copilot AI requested a review from joelmartinez November 14, 2025 14:36
@joelmartinez joelmartinez marked this pull request as ready for review November 15, 2025 00:40
@joelmartinez joelmartinez merged commit a031b3e into main Nov 15, 2025
2 checks passed
@joelmartinez joelmartinez deleted the copilot/fix-partial-rendering-issue branch November 15, 2025 00:42
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.

Inconsistent Partial rendering behavior

2 participants