Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Partial Views referenced with relative paths are not recompiled after changing the .cshtml #5574

Closed
rihei opened this issue Nov 29, 2016 · 8 comments
Assignees

Comments

@rihei
Copy link

rihei commented Nov 29, 2016

It seems that when a partial view is referenced in ASP.NET Core MVC 1.0.1 by a relative path (../), changes to the partial view's .cshtml file require a build to take effect. Normally saving the changed .cshtml file and reloading the page in browser are enough to make the changes visible.

Minimal project to reproduce this: https://github.com/rihei/aspnetcoremvc-partialview-relativepath-bug/

In the test project, there are two partial views (one in Other folder and one in Shared). First prints "1" and second "A". When I edit them to print "2" and "B" instead, save the files and reload the page in browser, the relatively referenced partial views don't change. The same file referenced differently on the same page shows the new content instead.
image

@dougbu
Copy link
Member

dougbu commented Nov 29, 2016

Terminology: It's a bit strange but MVC performs view location expansion on view names such as "../Shared/_TestSharedPartial" i.e. they are names and not paths. The .cshtml suffix controls whether the given string is treated as a view name or a path. Paths are either absolute or relative, depending on whether they start with "/" or "@" (after canonicalization) or not.

Using the above terminology, view caching is working correctly for simple view names and absolute paths. But, both relative paths and more complicated view names confuse the system. Makes me wonder if the problem is the ".." portion of the names / paths you're testing.

@pranavkm ??

@pranavkm
Copy link
Contributor

Perhaps there's an issue with the watcher triggering on the resolved path versus Mvc listening on the unresolved path. I'll have a look.

@pranavkm
Copy link
Contributor

My hunch was right - IFileProvider.Watch registers a token for the file with the path given as is i.e. Views/Home/../Shared/_TestSharedPartial.cshtml which then fails to match when an event is raised for Views/Shared/_TestSharedPartial.cshtml (since those are just exact matches). It's essentially the same issue as aspnet/FileSystem#248.

That said, perhaps we use this as a reason to address the other .. issues in the view engine: aspnet/MvcPrecompilation#33. We should certainly fix aspnet/FileSystem#248, but if we invoke Watch using normalized paths, we wouldn't have seen this issue here. Thoughts @Eilon

pranavkm added a commit that referenced this issue Dec 8, 2016
This change moves the onus of path resolution from individual IFileProvider instances to RazorViewEngine.

Fixes #5574
Fixes aspnet/MvcPrecompilation#33
pranavkm added a commit that referenced this issue Dec 8, 2016
This change moves the onus of path resolution from individual IFileProvider instances to RazorViewEngine.

Fixes #5574
Fixes aspnet/MvcPrecompilation#33
pranavkm added a commit that referenced this issue Dec 8, 2016
This change moves the onus of path resolution from individual IFileProvider instances to RazorViewEngine.

Fixes #5574
Fixes aspnet/MvcPrecompilation#33
pranavkm added a commit that referenced this issue Dec 8, 2016
This change moves the onus of path resolution from individual IFileProvider instances to RazorViewEngine.

Fixes #5574
Fixes aspnet/MvcPrecompilation#33
@pranavkm pranavkm self-assigned this Dec 8, 2016
@pranavkm pranavkm added the bug label Dec 8, 2016
@pranavkm pranavkm added this to the 1.2.0 milestone Dec 8, 2016
@rihei
Copy link
Author

rihei commented Nov 21, 2017

This bug still seems to be present in asp.net core 2.0.1? Has the fix been published?

@pranavkm
Copy link
Contributor

@rihei the issue should have been fixed in 2.0.0. Is https://github.com/rihei/aspnetcoremvc-partialview-relativepath-bug/ still a good sample that reproduces the problem?

@rihei
Copy link
Author

rihei commented Nov 21, 2017

I updated the sample project to the newest versions, and investigated a bit more. The problem seems to be partly fixed: relative path to a partial view now works if the ".cshtml" extension is present in the path. The view still doesn't show the changed content if the partial view is referenced by relative path and no ".cshtml".

Here I have first set the two partial views to print "1" and "A", then started the project and loaded the view in the browser, then edited them to print "2" and "B" and reloaded the browser view. The same partial produces different content based on how it's referenced. Wrong kind of reference shows the old content, even though the very same file produces new content on the same page when referenced the right way.

image

@pranavkm
Copy link
Contributor

@rihei we made further changes to the look up behavior as part of the (yet to be released) 2.1.0 release. See #6672. For the 2.0.0 release, you must have an cshtml extension for the view engine to treat the string as a path (and not a name to look up).

@rihei
Copy link
Author

rihei commented Nov 22, 2017

Ok, I expect this to be fixed in 2.1.0 then. Thank you! At the moment you cannot notice that a reference is somehow wrong until the site is already running and edits to the partial view don't take effect.

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

No branches or pull requests

3 participants