From e499473f82c0f25423bc38a9822a8fa057435363 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 21 Oct 2024 14:15:00 +0800 Subject: [PATCH 1/3] Update single fetch deprecation notice to also include info about null Resource routes can no longer just return null, call this out in the deprecation notice. --- packages/remix-server-runtime/deprecations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/remix-server-runtime/deprecations.ts b/packages/remix-server-runtime/deprecations.ts index d6c25769cf8..a9612a4af06 100644 --- a/packages/remix-server-runtime/deprecations.ts +++ b/packages/remix-server-runtime/deprecations.ts @@ -4,7 +4,7 @@ export function resourceRouteJsonWarning( ) { return ( "⚠️ REMIX FUTURE CHANGE: Resource routes will no longer be able to " + - "return raw JavaScript objects in v3 when Single Fetch becomes the default. " + + "return null or 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 " + From 1d84a4640f907de3c339daf3a7c6d9702efdc456 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Oct 2024 13:19:48 -0400 Subject: [PATCH 2/3] Update deprecations.ts --- packages/remix-server-runtime/deprecations.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/remix-server-runtime/deprecations.ts b/packages/remix-server-runtime/deprecations.ts index a9612a4af06..1ccf4d384a2 100644 --- a/packages/remix-server-runtime/deprecations.ts +++ b/packages/remix-server-runtime/deprecations.ts @@ -3,11 +3,11 @@ export function resourceRouteJsonWarning( routeId: string ) { return ( - "⚠️ REMIX FUTURE CHANGE: Resource routes will no longer be able to " + - "return null or 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" ); } From ef53b7ea4d0bcd75d95f82043396b4c9cb3c84cb Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Tue, 22 Oct 2024 07:22:27 +0800 Subject: [PATCH 3/3] Add tests --- .changeset/grumpy-llamas-leave.md | 5 ++++ integration/single-fetch-test.ts | 46 +++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 .changeset/grumpy-llamas-leave.md diff --git a/.changeset/grumpy-llamas-leave.md b/.changeset/grumpy-llamas-leave.md new file mode 100644 index 00000000000..f838030d4df --- /dev/null +++ b/.changeset/grumpy-llamas-leave.md @@ -0,0 +1,5 @@ +--- +"@remix-run/server-runtime": patch +--- + +Update externally-accessed resource routes warning to cover null usage as well diff --git a/integration/single-fetch-test.ts b/integration/single-fetch-test.ts index 10c9c62bf97..d632cbe1856 100644 --- a/integration/single-fetch-test.ts +++ b/integration/single-fetch-test.ts @@ -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; });