From 3793b281641ecb13a29ccf41d9992883fc7d4e81 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 8 Oct 2024 15:46:17 +0100 Subject: [PATCH] Interactivity API: Improvements to the experimental full-page navigation (#64067) * fix: Add initial data population in interactivity router * chore: Update element.innerText to element.textContent in head.ts file * feat: Exclude src and href attributes when copying head element attributes * chore: Populate initial data in interactivity router * chore: Move Populate initial data in interactivity router * Wait for `load` event of script element before returning from `fetchHeadAssets()` function * feat: Update head tags to improve prefetching of scripts and stylesheets This commit modifies the `updateHead` function in `head.ts` to improve support for lazy loading of scripts and stylesheets. It preloades the script modules using `modulepreload`, imports the necessary scripts using dynamic imports and adds the `preload` link elements for stylesheets. * Do not load interactivity script modules in development mode when full page navigation is enabled * Format interactivity-api.php * Update interactivity script module registration to use version from asset files - Added logic to retrieve version information from `index.min.asset.php` and `router.min.asset.php` files. - Updated `wp_register_script_module` calls to use the retrieved version instead of the default version when full-page navigation is not enabled. * empty commit * Rename populateInitialData to populateServerData * remove populateServerData * try: remove the webpack comment * try: remove the await import() * bring back the async import * Move headElements to head.ts * Revert "try: remove the webpack comment" This reverts commit 62e527e1769162894881eba76fc33bd96e3fa7eb. * default_version => router_version * Remove the changes to interactivity-api.php * Make `renderRegions` async * Update TS type of the stylesheets variable Co-authored-by: Jon Surrell * Replace Array.from() with direct forEach() on NodeList in head.ts: * Check if href is null * Clarify why we only prefetch script modules * Add changelog --------- Co-authored-by: michalczaplinski Co-authored-by: DAreRodz Co-authored-by: sirreal Co-authored-by: gziolo Co-authored-by: luisherranz Co-authored-by: westonruter --- packages/interactivity-router/CHANGELOG.md | 8 ++ packages/interactivity-router/src/head.ts | 114 ++++++++++++--------- packages/interactivity-router/src/index.ts | 56 +++++----- 3 files changed, 106 insertions(+), 72 deletions(-) diff --git a/packages/interactivity-router/CHANGELOG.md b/packages/interactivity-router/CHANGELOG.md index 7878796b9004cc..4f794899096683 100644 --- a/packages/interactivity-router/CHANGELOG.md +++ b/packages/interactivity-router/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +### Enhancements + +- Improvements to the experimental full-page navigation ([#64067](https://github.com/WordPress/gutenberg/pull/64067)): + - Remove the `src` attributes from prefetched script tags. + - Use `.textContent` instead of `.innerText` to set `