Sitemap not working properly

I think I missing something but can’t figure out what it is and hope someone can help out.

Using the Demo theme in OC4 for a website with multisite (2 languages).
I’ve 2 things that occurs with the sitemap.

  1. The alternative links output show Default instead of the right page URL:
    <xhtml:link rel=“alternative” hreflang=“en” href=“https://domain.ext/en/default”/>

  2. When I’m switching these on, I’m getting an error:

Include nested items. 
Nested items could be generated dynamically by supported page references.  

Replace this item with its generated children. 
Use this checkbox to push generated menu items to the same level with this item. This item itself will be hidden.

Getting this error in my log:
ErrorException: foreach() argument must be of type array|object, null given in /var/www/vhosts/domain.ext/httpdocs/modules/tailor/classes/blueprintindexer/PageManagerRegistry.php:193

{#- Look for a specific blueprint code/slug -#}
{% if sitemap is empty %}
    {% do abort(500, "A menu definition with code 'sitemap' was not found. Please create this menu in the Admin Panel using the Content → Menus page.") %}
{% endif %}

{#- Function to render a sitemap item, including children -#}
{% macro render_sitemap_item(item, reference, isRoot) %}
    {% import _self as nav %}
    {% set hideRootItem = isRoot and item.replace %}
    {% if reference.url and not hideRootItem %}
        <url>
            <loc>{{ reference.url }}</loc>
            <lastmod>{{ reference.mtime|date('c') }}</lastmod>
            <changefreq>{{ item.changefreq }}</changefreq>
            <priority>{{ item.priority }}</priority>

            {#- Multisite implementation -#}
            {% if reference.sites %}
                {% for site in reference.sites %}
                    <xhtml:link rel="alternative" hreflang="{{ site.locale }}" href="{{ site.url }}" />
                {% endfor %}
            {% endif %}
        </url>
    {% endif %}

    {#- Render child items -#}
    {% if reference.items %}
        {% for child in reference.items %}
            {{ nav.render_sitemap_item(item, child) }}
        {% endfor %}
    {% endif %}
    
{% endmacro %}
{% import _self as nav %}
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xhtml="https://www.w3.org/1999/xhtml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
>
    {% for item in sitemap.sitemap_items %}
        {{ nav.render_sitemap_item(
            item,
            link(item.reference, { nesting: item.nesting, sites: true }),
            true
        ) }}
    {% endfor %}
</urlset>

TAILOR:

uuid: 85e471d2-09b9-4f3d-a63b-1ae9d92d2879
handle: Site\Menus
type: entry
name: Menu
multisite: true
drafts: false
pagefinder: false

customMessages:
    buttonCreate: New Menu

navigation:
    label: Menus
    icon: icon-sitemap
    order: 205
    parent: Content\Page

columns:
    title:
        label: Title
    entry_type_name:
        label: Menu Type
        invisible: false
    slug:
        label: Code
        invisible: false

fields:
    slug:
        label: Code
        validation:
            - required

groups:
    regular_menu:
        name: Regular Menu
        fields:
            items:
                label: Menu Items
                type: nesteditems
                span: adaptive
                maxDepth: 0
                customMessages:
                    buttonCreate: Add Item
                    titleCreateForm: Create Item
                    titleUpdateForm: Edit Item
                form:
                    fields:
                        title:
                            label: Title
                            tab: Reference
                            default: New Menu Item
                            span: full
                            type: text
                            autoFocus: true
                            validation:
                                - required

                        reference:
                            label: Reference
                            type: pagefinder
                            tab: Reference
                    tabs:
                        fields:
                            _menu_item:
                                type: mixin
                                source: Site\Menus\MenuItem

    sitemap_menu:
        name: Sitemap Menu
        fields:
            sitemap_items:
                label: Sitemap Items
                type: nesteditems
                span: adaptive
                maxDepth: 1
                customMessages:
                    buttonCreate: Add Sitemap Item
                    titleCreateForm: Create Sitemap Item
                    titleUpdateForm: Edit Sitemap Item
                form:
                    fields:
                        title:
                            label: Title
                            tab: Reference
                            default: New Menu Item
                            span: full
                            type: text
                            autoFocus: true
                            validation:
                                - required

                        reference:
                            label: Reference
                            type: pagefinder
                            tab: Reference
                    tabs:
                        fields:
                            _menu_item:
                                type: mixin
                                source: Site\Menus\SitemapItem

Update
I have it partialy working at the moment.
The sitemap can be generated as I moved it from the menu (demo theme) to a stand alone Blueprint.

However, the problem when I switch the Include Nested Items and/or Replace this item with its generated children on, it still gives me an error.

@daft, any idea on this?
I’m using V4, fully updated and build from scratch (no upgrade from v3 > v4).

Blueprint

handle: Site\Sitemap
type: structure
name: Sitemap
drafts: false
pagefinder: false

structure:
    maxDepth: 1

navigation:
    parent: settings
    icon: icon-sitemap
    description: Specify pages to appear in the sitemap for your website.
    category: CATEGORY_CMS

fields:
    reference:
        label: Reference
        type: pagefinder

    priority:
        label: Priority
        commentAbove: The priority of this URL relative to other URLs on your site.
        type: radio
        inlineOptions: true
        options:
            '0.1': '0.1'
            '0.2': '0.2'
            '0.3': '0.3'
            '0.4': '0.4'
            '0.5': '0.5'
            '0.6': '0.6'
            '0.7': '0.7'
            '0.8': '0.8'
            '0.9': '0.9'
            '1.0': '1.0'

    changefreq:
        commentAbove: How frequently the page is likely to change.
        label: Change Frequency
        type: radio
        inlineOptions: true
        options:
            always: Always
            hourly: Hourly
            daily: Daily
            weekly: Weekly
            monthly: Monthly
            yearly: Yearly
            never: Never

    nesting:
        label: Include nested items
        shortLabel: Nesting
        comment: Nested items could be generated dynamically by supported page references.
        type: checkbox

    replace:
        label: Replace this item with its generated children
        comment: Use this checkbox to push generated menu items to the same level with this item. This item itself will be hidden.
        type: checkbox
        column: false
        scope: false
        trigger:
            action: disable|empty
            field: nesting
            condition: unchecked

CMS Page

{#- Look for a specific blueprint code/slug -#}
{#% if sitemap is empty %}
    {% do abort(500, "A menu definition with code 'sitemap' was not found. Please create this menu in the Admin Panel using the Content → Menus page.") %}
{% endif %#}

{% macro render_sitemap_item(item, reference, isRoot) %}
    {% import _self as nav %}
    {% set hideRootItem = isRoot and item.replace %}
    {% if reference.url and not hideRootItem %}
        <url>
            <loc>{{ reference.url }}</loc>
            <lastmod>{{ reference.mtime|date('c') }}</lastmod>
            <changefreq>{{ item.changefreq }}</changefreq>
            <priority>{{ item.priority }}</priority>

            {#- Multisite implementation -#}
            {% if reference.sites %}
                {% for site in reference.sites %}
                    <xhtml:link rel="alternative" hreflang="{{ site.locale }}" href="{{ site.url }}" />
                {% endfor %}
            {% endif %}
        </url>
    {% endif %}

    {#- Render child items -#}
    {% if reference.items %}
        {% for child in reference.items %}
            {{ nav.render_sitemap_item(item, child) }}
        {% endfor %}
    {% endif %}
{% endmacro %}
{% import _self as nav %}
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xhtml="https://www.w3.org/1999/xhtml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
>
    {% for item in sitemap %}
        {{ nav.render_sitemap_item(
            item,
            link(item.reference, { nesting: item.nesting, sites: true }),
            true
        ) }}
    {% endfor %}
</urlset>