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

RRR Rendering Follow Ups #4885

Merged
merged 15 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickSubmitButton(HAS_BOUNDARY_ACTION);
await page.waitForSelector("#own-boundary");
await page.waitForSelector(`text=${OWN_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(OWN_BOUNDARY_TEXT);
});

Expand All @@ -315,7 +315,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto(HAS_BOUNDARY_ACTION);
await app.clickSubmitButton(HAS_BOUNDARY_ACTION);
await page.waitForSelector("#own-boundary");
await page.waitForSelector(`text=${OWN_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(OWN_BOUNDARY_TEXT);
});

Expand All @@ -332,6 +332,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickSubmitButton(NO_BOUNDARY_ACTION);
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(ROOT_BOUNDARY_TEXT);
});

Expand All @@ -341,6 +342,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto(NO_BOUNDARY_ACTION);
await app.clickSubmitButton(NO_BOUNDARY_ACTION);
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(ROOT_BOUNDARY_TEXT);
});

Expand All @@ -354,6 +356,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickLink(HAS_BOUNDARY_LOADER);
await page.waitForSelector(`text=${OWN_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(OWN_BOUNDARY_TEXT);
});

Expand All @@ -369,6 +372,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickLink(NO_BOUNDARY_LOADER);
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(ROOT_BOUNDARY_TEXT);
});

Expand All @@ -384,6 +388,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickLink(NO_BOUNDARY_RENDER);
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(ROOT_BOUNDARY_TEXT);
});

Expand All @@ -397,6 +402,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickLink(HAS_BOUNDARY_RENDER);
await page.waitForSelector(`text=${OWN_BOUNDARY_TEXT}`);
expect(await app.getHtml("main")).toMatch(OWN_BOUNDARY_TEXT);
});

Expand Down Expand Up @@ -429,7 +435,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/fetcher-no-boundary");
await app.clickSubmitButton(NO_BOUNDARY_NO_LOADER_OR_ACTION);
await page.waitForSelector("#root-boundary");
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
});

test("renders root boundary in document POST without action requests", async () => {
Expand All @@ -446,7 +452,7 @@ test.describe("ErrorBoundary", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await app.clickSubmitButton(NO_BOUNDARY_NO_LOADER_OR_ACTION);
await page.waitForSelector("#root-boundary");
await page.waitForSelector(`text=${ROOT_BOUNDARY_TEXT}`);
});

test("renders own boundary in document POST without action requests", async () => {
Expand Down
52 changes: 38 additions & 14 deletions integration/form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ test.describe("Forms", () => {
let actionData = useActionData();
return (
<div onClick={(event) => event.stopPropagation()}>
<pre>{JSON.stringify(actionData)}</pre>
{actionData ? <pre id="action-data">{JSON.stringify(actionData)}</pre> : null}
<Form method="post">
<button type="submit" name="intent" value="add">Add</button>
</Form>
Expand Down Expand Up @@ -332,7 +332,8 @@ test.describe("Forms", () => {
<button>Submit</button>
<button formMethod={submitterFormMethod}>Submit with {submitterFormMethod}</button>
</Form>
<pre>{actionData || loaderData}</pre>
{actionData ? <pre id="action-method">{actionData}</pre> : null}
<pre id="loader-method">{loaderData}</pre>
</>
)
}
Expand Down Expand Up @@ -524,14 +525,18 @@ test.describe("Forms", () => {
await page.waitForSelector(`pre:has-text("${SQUID_INK_HOTDOG}")`);
});

test("when clicking on a submit button as a descendant of an element that stops propagation on click, still passes the clicked submit button's `name` and `value` props to the request payload", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/stop-propagation");
await app.clickSubmitButton("/stop-propagation", { wait: true });
expect(await app.getHtml()).toMatch('{"intent":"add"}');
});
test(
"when clicking on a submit button as a descendant of an element that " +
"stops propagation on click, still passes the clicked submit button's " +
"`name` and `value` props to the request payload",
async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/stop-propagation");
await app.clickSubmitButton("/stop-propagation", { wait: true });
await page.waitForSelector("#action-data");
expect(await app.getHtml()).toMatch('{"intent":"add"}');
}
);

test.describe("<Form> action", () => {
test.describe("in a static route", () => {
Expand Down Expand Up @@ -789,6 +794,7 @@ test.describe("Forms", () => {
html = await app.getHtml();
el = getElement(html, `#${INDEX_ROUTE_NO_ACTION_POST}`);
expect(el.attr("action")).toBe("/blog?index&junk=1");
await page.waitForURL(/\/blog\?index&junk=1$/);
expect(app.page.url()).toMatch(/\/blog\?index&junk=1$/);
});
});
Expand Down Expand Up @@ -946,9 +952,17 @@ test.describe("Forms", () => {
);

let app = new PlaywrightFixture(appFixture, page);
await app.goto(`/form-method?method=${method}`);
await app.goto(`/form-method?method=${method}`, true);
await app.clickElement(`text=Submit`);
expect(await app.getHtml("pre")).toBe(`<pre>${method}</pre>`);
if (method !== "GET") {
await page.waitForSelector("#action-method");
expect(await app.getHtml("pre#action-method")).toBe(
`<pre id="action-method">${method}</pre>`
);
}
expect(await app.getHtml("pre#loader-method")).toBe(
`<pre id="loader-method">GET</pre>`
);
});
});
});
Expand All @@ -963,10 +977,19 @@ test.describe("Forms", () => {
}) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto(
`/form-method?method=${method}&submitterFormMethod=${overrideMethod}`
`/form-method?method=${method}&submitterFormMethod=${overrideMethod}`,
true
);
await app.clickElement(`text=Submit with ${overrideMethod}`);
expect(await app.getHtml("pre")).toBe(`<pre>${overrideMethod}</pre>`);
if (overrideMethod !== "GET") {
await page.waitForSelector("#action-method");
expect(await app.getHtml("pre#action-method")).toBe(
`<pre id="action-method">${overrideMethod}</pre>`
);
}
expect(await app.getHtml("pre#loader-method")).toBe(
`<pre id="loader-method">GET</pre>`
);
});
});
});
Expand Down Expand Up @@ -1060,6 +1083,7 @@ test.describe("Forms", () => {
// This submission should ignore the index route and the pathless layout
// route above it and hit the action in routes/pathless-layout-parent.jsx
await app.clickSubmitButton("/pathless-layout-parent");
await page.waitForSelector("text=Submitted - Yes");
expect(await app.getHtml()).toMatch("Submitted - Yes");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ const exportsByRenderer: Record<Renderer, Partial<ExportNames>> = {
"NavLinkProps",
"RemixBrowserProps",
"RemixServerProps",
"ShouldReloadFunction",
"SubmitFunction",
"SubmitOptions",
"ThrownResponse",
Expand Down
11 changes: 1 addition & 10 deletions packages/remix-eslint-config/rules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,7 @@ module.exports = {
"no-new-object": WARN,
"no-octal": WARN,
"no-redeclare": ERROR,
"no-restricted-imports": [
WARN,
...replaceRemixImportsOptions,
{
importNames: ["useTransition"],
message:
"useTransition is deprecated in favor of useNavigation as of v1.9.0.",
name: "@remix-run/react",
},
],
"no-restricted-imports": [WARN, ...replaceRemixImportsOptions],
"no-script-url": WARN,
"no-self-assign": WARN,
"no-self-compare": WARN,
Expand Down
1 change: 0 additions & 1 deletion packages/remix-eslint-config/rules/packageExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const reactSpecificExports = {
"NavLinkProps",
"RemixBrowserProps",
"RemixServerProps",
"ShouldReloadFunction",
"SubmitFunction",
"SubmitOptions",
"ThrownResponse",
Expand Down
131 changes: 82 additions & 49 deletions packages/remix-react/__tests__/components-test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react";
import { MemoryRouter } from "react-router-dom";
import { createMemoryRouter, RouterProvider } from "react-router-dom";
import { fireEvent, render, act } from "@testing-library/react";

import type { LiveReload as ActualLiveReload } from "../components";
import { Link, NavLink, RemixEntryContext } from "../components";
import { Link, NavLink, RemixContext } from "../components";

import "@testing-library/jest-dom/extend-expect";

Expand Down Expand Up @@ -77,75 +77,108 @@ function itPrefetchesPageLinks<
Props extends { to: any; prefetch?: any } & PrefetchEventHandlerProps
>(Component: React.ComponentType<Props>) {
describe('prefetch="intent"', () => {
let context = {
routeModules: { idk: { default: () => null } },
manifest: {
routes: {
idk: {
hasLoader: true,
hasAction: false,
hasCatchBoundary: false,
hasErrorBoundary: false,
id: "idk",
module: "idk.js",
},
},
entry: { imports: [], module: "" },
url: "",
version: "",
},
future: { v2_meta: false },
};

beforeEach(() => {
jest.useFakeTimers();
});

function withContext(stuff: JSX.Element) {
let context = {
routeModules: { idk: { default: () => null } },
manifest: {
routes: {
idk: {
hasLoader: true,
hasAction: false,
hasCatchBoundary: false,
hasErrorBoundary: false,
setIntentEvents.forEach((event) => {
it(`prefetches page links on ${event}`, () => {
let router;

act(() => {
router = createMemoryRouter([
{
id: "root",
path: "/",
element: (
<Component {...({ to: "idk", prefetch: "intent" } as Props)} />
),
},
{
id: "idk",
module: "idk",
path: "idk",
loader: () => null,
element: <h1>idk</h1>,
},
},
entry: { imports: [], module: "" },
url: "",
version: "",
},
matches: [],
clientRoutes: [
{ id: "idk", path: "idk", hasLoader: true, element: "", module: "" },
],
routeData: {},
appState: {} as any,
transitionManager: {} as any,
};
return (
<RemixEntryContext.Provider value={context}>
<MemoryRouter>{stuff}</MemoryRouter>
</RemixEntryContext.Provider>
);
}
]);
});

setIntentEvents.forEach((event) => {
it(`prefetches page links on ${event}`, () => {
let { container, unmount } = render(
withContext(
<Component {...({ to: "idk", prefetch: "intent" } as Props)} />
)
<RemixContext.Provider value={context}>
<RouterProvider router={router} />
</RemixContext.Provider>
);

fireEvent[event](container.firstChild);
act(() => {
jest.runAllTimers();
});

expect(container.querySelector("link[rel=prefetch]")).toBeTruthy();
let dataHref = container
.querySelector('link[rel="prefetch"][as="fetch"]')
?.getAttribute("href");
expect(dataHref).toBe("/idk?_data=idk");
let moduleHref = container
.querySelector('link[rel="modulepreload"]')
?.getAttribute("href");
expect(moduleHref).toBe("idk.js");
unmount();
});

it(`prefetches page links and calls explicit handler on ${event}`, () => {
let router;
let ranHandler = false;
let eventHandler = `on${event[0].toUpperCase()}${event.slice(1)}`;
act(() => {
router = createMemoryRouter([
{
id: "root",
path: "/",
element: (
<Component
{...({
to: "idk",
prefetch: "intent",
[eventHandler]: () => {
ranHandler = true;
},
} as any)}
/>
),
},
{
id: "idk",
path: "idk",
loader: () => true,
element: <h1>idk</h1>,
},
]);
});

let { container, unmount } = render(
withContext(
<Component
{...({
to: "idk",
prefetch: "intent",
[eventHandler]: () => {
ranHandler = true;
},
} as any)}
/>
)
<RemixContext.Provider value={context}>
<RouterProvider router={router} />
</RemixContext.Provider>
);

fireEvent[event](container.firstChild);
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-react/__tests__/scroll-restoration-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function AppShell({ children }: { children: React.ReactNode }) {
);
}

describe("<ScrollRestoration />", () => {
// TODO: Fix in ScrollRestoration branch
describe.skip("<ScrollRestoration />", () => {
function withContext(stuff: JSX.Element) {
let context: RemixEntryContextType = {
routeModules: { idk: { default: () => null } },
Expand Down
Loading