Preview: Fixes a potential issue where the preview URL could be a different backoffice host (#20591)

* hotfix: ensures that local urls stay relative so we land up on the correct backoffice host that the user initiated the preview session from originally

* feat: since ensureAbsoluteUrl is never supplied anymore, we can remove the parameter altogether

* Remove unused dependency

* Expose IsExternal for URLs

* feat: adds localize controller

* chore: generates api models

* feat: marks the internal preview default url as relative, so that the `<base>` tag is taken into consideration - that way the URL will open on whatever host is active

* Remove IsExternal from the API again

* regenerate types

---------

Co-authored-by: kjac <kja@umbraco.dk>
This commit is contained in:
Jacob Overgaard
2025-10-22 09:48:55 +02:00
committed by GitHub
parent 6effe32136
commit 63ae29a1aa
3 changed files with 13 additions and 12 deletions

View File

@@ -144,7 +144,7 @@ public class NewDefaultUrlProvider : IUrlProvider
public Task<UrlInfo?> GetPreviewUrlAsync(IContent content, string? culture, string? segment)
=> Task.FromResult<UrlInfo?>(
UrlInfo.AsUrl(
$"/{Constants.System.UmbracoPathSegment}/preview?id={content.Key}&culture={culture}&segment={segment}",
$"preview?id={content.Key}&culture={culture}&segment={segment}",
Alias,
culture,
isExternal: false));
@@ -182,7 +182,7 @@ public class NewDefaultUrlProvider : IUrlProvider
// We have the published content now, so we can check if the culture is published, and thus avoid the DB hit.
string route;
var isDraft = _umbracoContextAccessor.GetRequiredUmbracoContext().InPreviewMode;
if(isDraft is false && string.IsNullOrWhiteSpace(culture) is false && content.Cultures.Any() && content.IsInvariantOrHasCulture(culture) is false)
if (isDraft is false && string.IsNullOrWhiteSpace(culture) is false && content.Cultures.Any() && content.IsInvariantOrHasCulture(culture) is false)
{
route = "#";
}