umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

Custom view path picker for Block List picks wrong path #12079

Closed arknu closed 2 years ago

arknu commented 2 years ago

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.3.1

Bug summary

In ASP.NET Core, static files (like .html files) should be stored in the ~/wwwroot folder. This includes HTML files used for custom views in the Block List editor as well as stylesheets.

However, when browsing for a view during development, you are presented with a browser for the root of the site, which is wrong. You should only see the contents of the ~/wwwroot folder. Picking a view here results in the whole physical path being picked, including the ~/wwwroot folder, for example ~/wwwroot/Preview/block.html is picked as the path, which is incorrect. The correct path would be ~/Preview/block.html, excluding the "wwwroot" part.

This incorrect path then results in a 404 when Umbraco attempts to locate the view, since ASP.NET Core will treat the ~/wwwroot folder as the root for serving static files.

This problem only occurs during development. Once you deploy, the ~/wwwroot folder no longer exists.

Also, this only affects Custom views. Custom stylesheets work just fine and pick the correct path.

Specifics

No response

Steps to reproduce

  1. Create a Block List editor and add a block.
  2. Create a block and add it
  3. Create a custom view for the block in the ~/wwwroot folder
  4. Add the custom view in the block list editor
  5. Note that the wrong path is picked
  6. Attempt to add the block in the content editor. You will get a 404, since Umbraco is using the incorrect path.

Expected result / actual result

At a minimum the ~/wwwroot folder should be removed from the picked path.

However, I think we should really only show files in the ~/wwwroot folder, since that is where the files should be placed anyway.

nul800sebastiaan commented 2 years ago

Hey @arknu - the views are supposed to go in the ~/App_Plugins/{MyBlockEditor}/Views, not in ~/wwwroot. Really, ~/wwwroot is only used for Umbraco's static assets, we don't expect custom files to end up there.

I do agree we need to prescribe the view location better in the picker and wwwroot should not be available for picking.

There's an older discussion here about it which didn't conclude it looks like: https://github.com/umbraco/Umbraco-CMS/issues/8890

arknu commented 2 years ago

@nul800sebastiaan Interesting. That's the first time I have heard that path mentioned for custom views. In v8 I just used ~/Previews, which logically maps to ~/wwwroot/Previews in v9.

I'd disagree about ~/wwwroot not being used for anything else. Media goes in there, as does compiled CSS and static images in our normal builds. So it would only be natural to assume that static HTML files would go in there as well. After all, that is the normal way things work in ASP.NET Core. Static files go in ~/wwwroot and I think Umbraco should follow this convention.

nul800sebastiaan commented 2 years ago

Fair enough! The new setup is still a bit confusing, not yet used to it! 😅

I think @Zeegaan is putting in a fix for this but won't that break existing picked custom views?

While I was typing.. I thought I'd just test it, seems like it will work okay! So you're seeing me, after applying the PR, open an existing block list editor with custom view, resaving it, that all still works, then picking a new view and now we're scoped to the wwwroot directory, which seems good and the new picked view works as well.

https://user-images.githubusercontent.com/304656/157238026-9bad8a09-0e22-403a-b61d-6aa66fba8c57.mp4

elit0451 commented 2 years ago

Fixed in: https://github.com/umbraco/Umbraco-CMS/pull/12104