Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API : Refactor interactivity-router to TS #61730

Merged
merged 5 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Migrate head.js to TypeScript
  • Loading branch information
michalczaplinski committed May 16, 2024
commit 2fe4d93c37fc8ee65658483e7552610b61f47cd0
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* @async
* @param {Array} newHead The head elements of the new page.
*/
export const updateHead = async ( newHead ) => {
export const updateHead = async ( newHead: HTMLHeadElement[] ) => {
// Helper to get the tag id store in the cache.
const getTagId = ( tag ) => tag.id || tag.outerHTML;

@@ -41,12 +41,17 @@ export const updateHead = async ( newHead ) => {
* Fetches and processes head assets (stylesheets and scripts) from a specified document.
*
* @async
* @param {Document} doc The document from which to fetch head assets. It should support standard DOM querying methods.
* @param {Map} headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates.
* @param {Document} doc The document from which to fetch head assets. It should support standard DOM querying methods.
* @param {Map} headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Interactivity API package we are removing the type from the jsdoc to only leave it in TS.

* @param headElements.tag
* @param headElements.text
*
* @return {Promise<HTMLElement[]>} Returns an array of HTML elements representing the head assets.
*/
export const fetchHeadAssets = async ( doc, headElements ) => {
export const fetchHeadAssets = async (
doc: Document,
headElements: Map< string, { tag: Element; text: string } >
): Promise< HTMLElement[] > => {
const headTags = [];
const assets = [
{
4 changes: 2 additions & 2 deletions packages/interactivity-router/src/index.ts
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ interface VdomParams {

interface Page {
regions: Record< string, any >;
head: HTMLElement[];
head: HTMLHeadElement[];
title: string;
initialData: any;
}
@@ -54,7 +54,7 @@ const navigationMode: 'regionBased' | 'fullPage' =

// The cache of visited and prefetched pages, stylesheets and scripts.
const pages = new Map< string, Promise< Page | false > >();
const headElements = new Map();
const headElements = new Map< string, { tag: HTMLElement; text: string } >();

// Helper to remove domain and hash from the URL. We are only interesting in
// caching the path and the query.