Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/interactivity-router/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Deprecations

- Move `state.navigation.hasStarted` and `state.navigation.hasFinished` to a private store and deprecate direct access from the public `core/router` store. ([#70882](https://github.com/WordPress/gutenberg/pull/70882))

### Bug Fixes

- Update cached styles for re-fetched pages. ([#75097](https://github.com/WordPress/gutenberg/pull/75097))
Expand Down Expand Up @@ -41,8 +45,7 @@

- Preserve `media` attribute on intial style sheets after client-side navigation. ([70668](https://github.com/WordPress/gutenberg/pull/70668))

- Ignores `<noscript>` elements while preparing DOM. ([70905](https://github.com/WordPress/gutenberg/pull/70905))

- Ignores `<noscript>` elements while preparing DOM. ([70905](https://github.com/WordPress/gutenberg/pull/70905))

## 2.26.0 (2025-06-25)

Expand Down
10 changes: 0 additions & 10 deletions packages/interactivity-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ When loaded, this package [adds the following state and actions](https://github.
const { state, actions } = store( 'core/router', {
state: {
url: window.location.href,
navigation: {
hasStarted: false,
hasFinished: false,
texts: {
loading: '',
loaded: '',
},
message: '',
},
},
actions: {
*navigate(href, options) {...},
Expand Down Expand Up @@ -157,7 +148,6 @@ prefetch( url: string, options: PrefetchOptions = {} )
### State

`state.url` is a reactive property synchronized with the current URL.
Properties under `state.navigation` are meant for loading bar animations.

## Installation

Expand Down
30 changes: 25 additions & 5 deletions packages/interactivity-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
routerRegions,
h: createElement,
navigationSignal,
warn,
} = privateApis(
'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'
);
Expand Down Expand Up @@ -394,12 +395,28 @@ interface Store {
};
}

const { state: privateState } = store(
'core/router/private',
{
state: {
navigation: {
hasStarted: false,
hasFinished: false,
},
},
},
{ lock: true }
);

export const { state, actions } = store< Store >( 'core/router', {
state: {
url: window.location.href,
navigation: {
hasStarted: false,
hasFinished: false,
get navigation() {
if ( globalThis.SCRIPT_DEBUG ) {
warn(
`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`
);
}
return privateState.navigation;
},
},
actions: {
Expand Down Expand Up @@ -428,7 +445,7 @@ export const { state, actions } = store< Store >( 'core/router', {
}

const pagePath = getPagePath( href );
const { navigation } = state;
const { navigation } = privateState;
const {
loadingAnimation = true,
screenReaderAnnouncement = true,
Expand Down Expand Up @@ -546,6 +563,9 @@ export const { state, actions } = store< Store >( 'core/router', {
},
} );

// Initialize the URL in the state if it hasn't been set yet in the server.
state.url = state.url || window.location.href;

/**
* Announces a message to screen readers.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/interactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { directive } from './hooks';
import { getNamespace } from './namespaces';
import { parseServerData, populateServerData } from './store';
import { proxifyState } from './proxies';
import { deepReadOnly, navigationSignal, onDOMReady } from './utils';
import { deepReadOnly, navigationSignal, onDOMReady, warn } from './utils';

export {
store,
Expand Down Expand Up @@ -69,6 +69,7 @@ export const privateApis = (
routerRegions,
deepReadOnly,
navigationSignal,
warn,
};
}

Expand Down
Loading