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, CSS import in frontend #5257

Merged
merged 4 commits into from
Dec 31, 2024
Merged

Fix types, CSS import in frontend #5257

merged 4 commits into from
Dec 31, 2024

Conversation

jwhitlock
Copy link
Member

@jwhitlock jwhitlock commented Dec 10, 2024

When attempting to fix PR #5248, I found several typescript errors, and continued to get style warnings. This PR fixes those errors, most of which are in test code.

  • Convert next.config.js to next.config.ts, pass type checking
  • Add missing object members to mocked API calls, re-arrange object members to match type definition order
  • Switch fxaFlowTracker.test.ts to use a number for the time parameter instead of a string, matching the code
  • Switch to importing as import "react-toastify/dist/ReactToastify.css", to avoid dart sass warnings. This has the same declarations but with some additional space, which caused the CSS hash to change.
  • Reformat touched files

How to test:

  • cd frontend
  • npx tsc --noEmit runs with no warnings or errors
  • npm run test runs with all tests passing

This applies the same styles, but adds some spaces in the combined CSS.

This rule:

  height:calc(var(--g)*1px)

Becomes this rule:

  height:calc(var(--g) * 1px)

That's the same CSS rule, but it does cause a hash change from
58e1c80c0e503be3.css to 1b1c275d4655b992.css.
Copy link
Member

@groovecoder groovecoder left a comment

Choose a reason for hiding this comment

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

Some non-blocking questions/comments. Code looks good. Tests and spot-checks pass.

@@ -13,7 +13,7 @@ const mockedUseInboundContact = useInboundContact as jest.MockedFunction<
>;

export function getMockInboundContact(
inboundContact: Partial<InboundContact>
inboundContact: Partial<InboundContact> | undefined,
Copy link
Member

Choose a reason for hiding this comment

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

question (non-blocking): Why do we explicitly accept undefined data type here, and then explicitly pass undefined to this function? I also don't understand how this worked before where the code called getMockInboundContact() while this function definition seems to require an inboundContact parameter?

Copy link
Member

Choose a reason for hiding this comment

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

FYI this is what GitHub Copilot said:

The selection modifies the function getMockInboundContact to accept an additional data type, undefined, as a valid input for its inboundContact parameter. This change allows the function to be called without providing an argument, which is why the code now explicitly passes undefined when calling getMockInboundContact.

Previously, the code called getMockInboundContact() without any argument, which was possible because TypeScript allowed calling the function with an argument that was a partial InboundContact. However, with the updated type definition, the function now explicitly permits undefined, ensuring the function call remains valid even when no argument or an undefined argument is provided.

This change enhances the function's flexibility by allowing it to handle cases where the inboundContact parameter might be undefined, thereby preventing potential runtime errors.

@@ -7,7 +7,7 @@ import {
} from "react";
import Link from "next/link";
import { ToastContainer, Slide } from "react-toastify";
import "react-toastify/scss/main.scss";
import "react-toastify/dist/ReactToastify.css";
Copy link
Member

Choose a reason for hiding this comment

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

praise: ooo, this might also fix the CSS for the react-toastify 11.0.2 update.

Comment on lines +162 to +164
if (typeof allEntries[1].content !== "string") {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

TIL (via Copilot):

The if (typeof ...) { return; } block is not strictly necessary if the expect(typeof ...).toBe("string") call already ensures that allEntries[1].content is a string. However, the if block provides a safeguard to exit the function early if the type check fails, preventing any further execution that relies on the assumption that allEntries[1].content is a string. This can be useful to avoid runtime errors and make the test more robust.

@groovecoder
Copy link
Member

Yup. I rebased the react-toastify branch on this one and the build error is fixed AND the styling looks right.

@groovecoder groovecoder added this pull request to the merge queue Dec 31, 2024
Merged via the queue into main with commit b394293 Dec 31, 2024
32 checks passed
@groovecoder groovecoder deleted the frontend-fix-types branch December 31, 2024 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants