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

fix(types): pass types through memoize properly #10567

Merged
merged 6 commits into from
Mar 5, 2024
Merged

Conversation

LeoMcA
Copy link
Member

@LeoMcA LeoMcA commented Feb 21, 2024

Summary

Problem

While reviewing #10433 it annoyed me that memoize wasn't passing types through properly, and we were losing types in most of build/curriculum.ts because of this.

Solution

Pass through the types of the wrapped function in memoize, fix the things this breaks. (I suggest reviewing with ignore whitespace because one function gets majorly indented from these fixes).


How did you test this change?

yarn check:tsc

@LeoMcA LeoMcA requested a review from fiji-flo February 21, 2024 12:39
@LeoMcA LeoMcA requested a review from a team as a code owner February 21, 2024 12:39
@github-actions github-actions bot added the macros tracking issues related to kumascript macros label Feb 21, 2024
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

Very nice, just skimmed over, and left some comments.

@@ -37,7 +37,7 @@ export async function render(
selective_mode = false,
invalidateCache = false,
}: RenderOptions = {},
doc?: Doc
blogPost?: BlogPostDoc
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right. Why would kumascript.render() return a BlogPostDoc?

Copy link
Member Author

@LeoMcA LeoMcA Feb 21, 2024

Choose a reason for hiding this comment

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

It doesn't, this is the last argument, the return type is the line below (the Promise)

Copy link
Contributor

Choose a reason for hiding this comment

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

That should stay called doc it just replaces the Document.findByURL. And the type is tricky. Probably Doc as BlogPostDoc should just extend Doc but that is utterly broken right now.

Copy link
Contributor

@caugner caugner Feb 22, 2024

Choose a reason for hiding this comment

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

I don't think Doc applies here, as it has many more fields/requirements compared to BlogPostDoc.

BlogPostDoc:

yari/build/blog.ts

Lines 347 to 355 in 006eb85

interface BlogPostDoc {
url: string;
rawBody: string;
metadata: BlogPostMetadata & { locale: string };
isMarkdown: boolean;
fileInfo: {
path: string;
};
}

DocMetadata/Doc:

yari/libs/types/document.ts

Lines 128 to 159 in 006eb85

export interface DocMetadata {
title: string;
short_title: string;
locale: string;
native: string;
pageTitle: string;
mdn_url: string;
related_content: any[];
modified: string;
flaws: Flaws;
other_translations?: Translation[];
parents?: DocParent[];
source: Source;
contributors: string[];
isTranslated: boolean;
isActive: boolean;
hasMathML?: boolean;
isMarkdown: boolean;
summary: string;
popularity?: number; // Used for search.
noIndexing?: boolean;
browserCompat?: string[];
baseline?: SupportStatus;
hash?: string;
}
export interface Doc extends DocMetadata {
sidebarHTML: string;
sidebarMacro?: string;
toc: Toc[];
body: Section[];
}

@@ -14,7 +14,7 @@ import {
LIVE_SAMPLES_BASE_URL,
} from "../libs/env/index.js";
import { SourceCodeError } from "./src/errors.js";
import { Doc } from "../libs/types/document.js";
import { BlogPostDoc } from "../build/blog.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw should BlogPostDoc be moved into libs/types?

content/document.ts Show resolved Hide resolved
@LeoMcA LeoMcA changed the title chore(types): pass types through memoize properly fix(types): pass types through memoize properly Feb 21, 2024
@@ -8,7 +8,7 @@ const LANGUAGES = new Map(
})
);

type Translation = {
export type Translation = {
Copy link
Member

Choose a reason for hiding this comment

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

We can replace the type declaration here, as there was a duplicated one in libs/types/document.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, fixed in c00822d.

@github-actions github-actions bot added the merge conflicts 🚧 Please rebase onto or merge the latest main. label Feb 27, 2024
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot removed the merge conflicts 🚧 Please rebase onto or merge the latest main. label Feb 28, 2024
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

@LeoMcA Please have a look at the changes I pushed, but LGTM.

@caugner caugner merged commit ed9cbf3 into main Mar 5, 2024
14 checks passed
@caugner caugner deleted the fix-memoize-types branch March 5, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros tracking issues related to kumascript macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants