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

Update single fetch deprecation notice to also include info about null #10145

Merged
merged 3 commits into from
Oct 23, 2024
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
5 changes: 5 additions & 0 deletions .changeset/grumpy-llamas-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/server-runtime": patch
---

Update externally-accessed resource routes warning to cover null usage as well
46 changes: 40 additions & 6 deletions integration/single-fetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,12 +1687,46 @@ test.describe("single-fetch", () => {
});

expect(warnLogs).toEqual([
"⚠️ REMIX FUTURE CHANGE: Resource routes will no longer be able to return " +
"raw JavaScript objects in v3 when Single Fetch becomes the default. You " +
"can prepare for this change at your convenience by wrapping the data " +
"returned from your `loader` function in the `routes/resource` route with " +
"`json()`. For instructions on making this change see " +
"https://remix.run/docs/en/v2.9.2/guides/single-fetch#resource-routes",
"⚠️ REMIX FUTURE CHANGE: Externally-accessed resource routes will no longer be " +
"able to return raw JavaScript objects or `null` in React Router v7 when " +
"Single Fetch becomes the default. You can prepare for this change at your " +
`convenience by wrapping the data returned from your \`loader\` function in ` +
`the \`routes/resource\` route with \`json()\`. For instructions on making this ` +
"change, see https://remix.run/docs/en/v2.13.1/guides/single-fetch#resource-routes",
]);
console.warn = oldConsoleWarn;
});

test("wraps resource route 'null' returns in json with a deprecation warning", async () => {
let oldConsoleWarn = console.warn;
let warnLogs: unknown[] = [];
console.warn = (...args) => warnLogs.push(...args);

let fixture = await createFixture({
config: {
future: {
v3_singleFetch: true,
},
},
files: {
...files,
"app/routes/resource.tsx": js`
export function loader() {
return null;
}
`,
},
});
let res = await fixture.requestResource("/resource");
expect(await res.json()).toEqual(null);

expect(warnLogs).toEqual([
"⚠️ REMIX FUTURE CHANGE: Externally-accessed resource routes will no longer be " +
"able to return raw JavaScript objects or `null` in React Router v7 when " +
"Single Fetch becomes the default. You can prepare for this change at your " +
`convenience by wrapping the data returned from your \`loader\` function in ` +
`the \`routes/resource\` route with \`json()\`. For instructions on making this ` +
"change, see https://remix.run/docs/en/v2.13.1/guides/single-fetch#resource-routes",
]);
console.warn = oldConsoleWarn;
});
Expand Down
12 changes: 6 additions & 6 deletions packages/remix-server-runtime/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export function resourceRouteJsonWarning(
routeId: string
) {
return (
"⚠️ REMIX FUTURE CHANGE: Resource routes will no longer be able to " +
"return raw JavaScript objects in v3 when Single Fetch becomes the default. " +
"You can prepare for this change at your convenience by wrapping the data " +
`returned from your \`${type}\` function in the \`${routeId}\` route with ` +
"`json()`. For instructions on making this change see " +
"https://remix.run/docs/en/v2.9.2/guides/single-fetch#resource-routes"
"⚠️ REMIX FUTURE CHANGE: Externally-accessed resource routes will no longer be " +
"able to return raw JavaScript objects or `null` in React Router v7 when " +
"Single Fetch becomes the default. You can prepare for this change at your " +
`convenience by wrapping the data returned from your \`${type}\` function in ` +
`the \`${routeId}\` route with \`json()\`. For instructions on making this ` +
"change, see https://remix.run/docs/en/v2.13.1/guides/single-fetch#resource-routes"
);
}
Loading