AP.navigator.getLocation and query param page.id might point to wrong contentId

Dear community,

I just found out that AP.navigator.getLocation and the query param page.id might refer to the page visited before (not the current one) under the following conditions:

  • The current page is the home page of a space
  • The user used the breadcrumbs links to navigate to the space’s home page from another page in the space

Steps to reproduce:

  • Create a space with a home page and at least one child page
  • Ensure that you can use AP.navigator.getLocation on the space’s home page (alternative: have e.g. a webItem which consumes page.id)
  • Reload the space’s homepage and execute AP.navigator.getLocation - it returns the correct contentId
  • Navigate to a child page in the space
  • Navigate back to the space’s homepage using the breadcrumb links above the page’s title.
  • Execute AP.navigator.getLocation - its shows the contentId of the page visited before

Does anyone had similar issues?

Thank you

Andreas

1 Like

I hadn’t noticed that exact problem, but had noticed an issue with custom overview (home) pages in spaces - it reports the default page, not the details of the app (it returns a different object for general pages). BTW page.id is deprecated.

I have been able to replicate the issue.

The href field reported by getLocation reports the correct page, but the contentId is wrong (the previous page):
image
homepageId is the correct id, the contentId shown is the previous id.

In the interim, you could compare the href and reported contentId?

However, I have a webitem in the content tools menu and the query string reflects the correct info (including content.id/page.id).

1 Like

Dear @james.dellow

many thanks for looking into that.

You are right, the URL has the homepageId which I could use. However the content.id (thanks for pointing out the deprecation of page.id) is not correct for our webItem which points to a dialog.

 "dialogs": [{
		        "url": "/dialog?contentId={content.id}&spaceKey={space.key}",
		        "key": "some-key",
...
"webItems": [
        	{
                "location": "system.content.button",
                "context": "addon",
                "weight": 200,
                "target": {
                    "type": "dialogmodule",
                   	"options": {
      					"key": "some-key"
   					}
                },

The only thing I can is checking in the JS part whether the submitted id was correct comparing it to the homepageId as you suggested.

Thank you

Andreas

1 Like

@andreas1 , @james.dellow Short question: can you point me to documentation about deprecation of page.id and move to content.id?

It is here: Context parameters

page.id et al for dynamic content macros however don’t seem to be deprecated: https://developer.atlassian.com/cloud/confluence/modules/dynamic-content-macro/

Maybe Atlassian dropped the ball on this one and never finished the job?

Thanks for the replies!

@dmorrow Can you help us clarifying if page.id is indeed deprecated, as stated in Context parameters , or is is not deprecated, as documented in e.g. https://developer.atlassian.com/cloud/confluence/modules/dynamic-content-macro/ ?

I have the same issue. Is there a support ticket for this or do we just implement the workaround?

I have opened a ticket: Jira Service Management

For the time being this is my workaround for anybody dealing with the same:

const accountForHomePageBug = (location: Location) => {
    // When on a home page, getCurrentLocation() often incorrectly returns the previously visited page
    // Open ticket: https://ecosystem.atlassian.net/servicedesk/customer/portal/34/ECOHELP-43868
    // The actual homepage ID is contained in the href, so we modify the payload.
    try {
        const contentId: number = location.context.contentId;
        const href: string | undefined = location.href;
        if (href?.includes('homepageId')) {
            const parts = href.split('=');
            const homepageId = parseInt(parts[parts.length - 1], 10);
            if (contentId !== homepageId) {
                location.context.contentId = homepageId;
            }
        }
    } catch (error) {
        console.error(
            'An error occurred at getCurrentLocation():',
            error,
        );
    }
    return location;
};

Hi, everyone!
We know some of you have been waiting for years to have this fixed and we do apologize for that.
A partner raised a ticket about this issue a few days ago and we stumbled upon this old post with the same issue.
Please, be informed that https://jira.atlassian.com/browse/CONFCLOUD-79081 has been opened for this issue and hopefully it will be picked up for a fix soon.
Best!

2 Likes