Skip to content

Commit 1c3d585

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/webpack-isolated-source-eval
# Conflicts: # e2e/README.md # e2e/cases/media-query/queries.yak.ts # e2e/cases/yak-file-with-import/App.tsx # e2e/cases/yak-file-with-import/test.ts # e2e/package.json # e2e/run.ts # package.json # pnpm-lock.yaml
2 parents 87ea6c3 + 5ab65b4 commit 1c3d585

File tree

16 files changed

+150
-22
lines changed

16 files changed

+150
-22
lines changed

.changeset/multi-yak-e2e.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { styled } from "next-yak";
2+
import { spacing, brand } from "./tokens.yak.ts";
3+
4+
const Box = styled.div`
5+
padding: ${spacing}px;
6+
color: ${brand};
7+
`;
8+
9+
export default function App() {
10+
return <Box data-testid="box">Syntax error recovery</Box>;
11+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test, expect } from "@playwright/test";
2+
import { withTestEnv } from "next-yak-e2e";
3+
4+
test(
5+
"HMR recovers after a syntax error in a .yak.ts dependency",
6+
withTestEnv("hmr-yak-syntax-error-recovery", async (fsTmp, page) => {
7+
await page.goto(fsTmp.url);
8+
9+
const box = page.getByTestId("box");
10+
await expect(box).toHaveCSS("padding", "40px");
11+
await expect(box).toHaveCSS("color", "rgb(0, 128, 128)");
12+
13+
// Set marker to detect full page reloads
14+
await page.evaluate(() => {
15+
window.__hmr = true;
16+
});
17+
18+
// Introduce a syntax error in the .yak.ts file
19+
await fsTmp.writeFile(
20+
"tokens.yak.ts",
21+
"export const spacing = 5 * 8;\nexport const brand = <<<BROKEN>>>;\n",
22+
);
23+
24+
// Wait for the error to propagate
25+
await page.waitForTimeout(3_000);
26+
27+
// Fix the syntax error with new values
28+
await fsTmp.writeFile(
29+
"tokens.yak.ts",
30+
'export const spacing = 2 * 8;\nexport const brand = "red";\n',
31+
);
32+
33+
// After recovery, the new values should be applied
34+
await expect(box).toHaveCSS("padding", "16px", { timeout: 15_000 });
35+
await expect(box).toHaveCSS("color", "rgb(255, 0, 0)");
36+
37+
// Verify no full page reload occurred
38+
expect(await page.evaluate(() => window.__hmr)).toBe(true);
39+
}),
40+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const spacing = 5 * 8;
2+
export const brand = "teal";
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
export const screenQueries = {
2-
mobile: "@media (max-width: 599px)",
3-
};
1+
import { breakpoints } from "./screenSizes.ts";
2+
3+
/**
4+
* Example of a dynamic media query generator
5+
*
6+
* Proably not something you'd do in a real app, but it serves as a good test case for dynamic values in media queries
7+
*/
8+
const screenQueries = {} as Record<keyof typeof breakpoints, string>;
9+
10+
for (const [name, { min, max }] of Object.entries(breakpoints) as [
11+
keyof typeof breakpoints,
12+
{ min: number; max: number },
13+
][]) {
14+
const parts: string[] = [];
15+
if (min) parts.push(`(min-width: ${min}px)`);
16+
if (max) parts.push(`(max-width: ${max}px)`);
17+
screenQueries[name] = `@media ${parts.join(" and ")}`;
18+
}
19+
20+
export { screenQueries };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const breakpoints = {
2+
mobile: { min: 0, max: 599 },
3+
tablet: { min: 600, max: 899 },
4+
desktop: { min: 900, max: 1199 },
5+
wide: { min: 1200, max: 0 },
6+
} as const;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { styled } from "next-yak";
2+
import { spacing } from "./spacings.yak.ts";
3+
4+
const AccordionBox = styled.div`
5+
padding: ${spacing}px;
6+
`;
7+
8+
export function Accordion() {
9+
return <AccordionBox data-testid="accordion">Accordion</AccordionBox>;
10+
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { styled } from "next-yak";
2-
import { spacing, brandColor } from "./tokens.yak.ts";
3-
4-
const Box = styled.div`
5-
padding: ${spacing}px;
6-
color: ${brandColor};
7-
`;
1+
import { Accordion } from "./Accordion.tsx";
2+
import { Button } from "./Button.tsx";
3+
import { Card } from "./Card.tsx";
84

95
export default function App() {
10-
return <Box data-testid="box">Yak file with import</Box>;
6+
return (
7+
<>
8+
<Accordion />
9+
<Button />
10+
<Card />
11+
</>
12+
);
1113
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { styled } from "next-yak";
2+
import { spacing } from "./spacings.yak.ts";
3+
import { primaryColor } from "./colors.yak.ts";
4+
5+
const StyledButton = styled.button`
6+
padding: ${spacing}px;
7+
color: ${primaryColor};
8+
`;
9+
10+
export function Button() {
11+
return <StyledButton data-testid="button">Button</StyledButton>;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { styled } from "next-yak";
2+
import { primaryColor } from "./colors.yak.ts";
3+
4+
const StyledCard = styled.div`
5+
color: ${primaryColor};
6+
`;
7+
8+
export function Card() {
9+
return <StyledCard data-testid="card">Card</StyledCard>;
10+
}

0 commit comments

Comments
 (0)