Skip to content

Commit

Permalink
Fix: - Update the title when using enhanced pagination. (#55446)
Browse files Browse the repository at this point in the history
* Add title update when using enhanced pagination

* Simplify code

* Use innertext to prevent character encoding

* Add changelog

* Add e2e test

* Fix code review recommendations
  • Loading branch information
cbravobernal authored Oct 20, 2023
1 parent 127f7d4 commit 6a2c92b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- Update the title when using enhanced pagination. ([#55446](https://github.com/WordPress/gutenberg/pull/55446))

## 2.5.0 (2023-10-18)

## 2.4.0 (2023-10-05)
Expand Down
7 changes: 5 additions & 2 deletions packages/interactivity/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const regionsToVdom = ( dom ) => {
const id = region.getAttribute( attrName );
regions[ id ] = toVdom( region );
} );

return { regions };
const title = dom.querySelector( 'title' )?.innerText;
return { regions, title };
};

// Prefetch a page. We store the promise to avoid triggering a second fetch for
Expand All @@ -76,6 +76,9 @@ const renderRegions = ( page ) => {
const fragment = getRegionRootFragment( region );
render( page.regions[ id ], fragment );
} );
if ( page.title ) {
document.title = page.title;
}
};

// Variable to store the current navigation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class InteractivityUtils {
content: `<!-- wp:${ block } /-->`,
status: 'publish' as 'publish',
date_gmt: '2023-01-01T00:00:00',
title: alias,
};

const { link } = await this.requestUtils.createPost( payload );
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/specs/interactivity/router-regions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ test.describe( 'Router regions', () => {
await page.getByTestId( 'back' ).click();
await expect( nestedRegionSsr ).toHaveText( 'content from page 1' );
} );

test( 'Page title is updated 2', async ( { page } ) => {
await expect( page ).toHaveTitle(
'router regions – page 1 – gutenberg'
);
await page.getByTestId( 'next' ).click();
await expect( page ).toHaveTitle(
'router regions – page 2 – gutenberg'
);
await page.getByTestId( 'back' ).click();
await expect( page ).toHaveTitle(
'router regions – page 1 – gutenberg'
);
} );
} );

0 comments on commit 6a2c92b

Please sign in to comment.