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

Add deprecations for future flags #10126

Merged
merged 4 commits into from
Oct 18, 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
6 changes: 6 additions & 0 deletions .changeset/rude-clocks-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@remix-run/dev": minor
---

- Log deprecation warnings for v3 future flags
- Add `@deprecated` annotations to `json`/`defer` utilities
10 changes: 9 additions & 1 deletion integration/vite-build-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ test.beforeAll(async () => {
},
plugins: [
mdx(),
remix(),
remix({
future: {
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
}
}),
],
});
`,
Expand Down
15 changes: 13 additions & 2 deletions integration/vite-css-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const files = {
`,
"app/entry.client.tsx": js`
import "./entry.client.css";

import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
Expand Down Expand Up @@ -156,7 +156,18 @@ const VITE_CONFIG = async (port: number) => dedent`

export default {
${await viteConfig.server({ port })}
plugins: [remix(), vanillaExtractPlugin()],
plugins: [
remix({
future: {
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
}
}),
vanillaExtractPlugin()
],
}
`;

Expand Down
20 changes: 18 additions & 2 deletions integration/vite-presets-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const files = {
assetsDir: "custom-assets-dir",
},
plugins: [remix({
future: {
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
},
presets: [
// Ensure user config is passed to remixConfig hook
{
Expand All @@ -35,7 +42,16 @@ const files = {
throw new Error("Remix user config doesn't have presets array.");
}

let expected = JSON.stringify({ appDirectory: "app"});
let expected = JSON.stringify({
future: {
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
},
appDirectory: "app",
});
let actual = JSON.stringify(restUserConfig);

if (actual !== expected) {
Expand All @@ -49,7 +65,7 @@ const files = {
return {};
},
},

// Ensure preset config takes lower precedence than user config
{
name: "test-preset",
Expand Down
52 changes: 52 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ export async function resolveConfig(
}
}

logFutureFlagWarnings(future);

return {
appDirectory,
cacheDirectory,
Expand Down Expand Up @@ -742,3 +744,53 @@ let disjunctionListFormat = new Intl.ListFormat("en", {
style: "long",
type: "disjunction",
});

function logFutureFlagWarning(args: { flag: string; message: string }) {
logger.warn(args.message, {
key: args.flag,
details: [
`You can use the \`${args.flag}\` future flag to opt-in early.`,
`-> https://remix.run/docs/en/2.13.1/start/future-flags#${args.flag}`,
],
});
}

export function logFutureFlagWarnings(future: FutureConfig) {
if (!future.v3_fetcherPersist) {
logFutureFlagWarning({
flag: "v3_fetcherPersist",
message: "Fetcher persistence behavior is changing in React Router v7",
});
}

if (!future.v3_lazyRouteDiscovery) {
logFutureFlagWarning({
flag: "v3_lazyRouteDiscovery",
message:
"Route discovery/manifest behavior is changing in React Router v7",
});
}

if (!future.v3_relativeSplatPath) {
logFutureFlagWarning({
flag: "v3_relativeSplatPath",
message:
"Relative routing behavior for splat routes is changing in React Router v7",
});
}

if (!future.v3_singleFetch) {
logFutureFlagWarning({
flag: "v3_singleFetch",
message: "Data fetching is changing to a single fetch in React Router v7",
});
}

if (!future.v3_throwAbortReason) {
logFutureFlagWarning({
flag: "v3_throwAbortReason",
message:
"The format of errors thrown on aborted requests is changing in React Router v7",
});
}
}
9 changes: 9 additions & 0 deletions packages/remix-server-runtime/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export type TypedResponse<T = unknown> = Omit<Response, "json"> & {
* This is a shortcut for creating `application/json` responses. Converts `data`
* to JSON and sets the `Content-Type` header.
*
* @deprecated This utility is deprecated in favor of opting into Single Fetch
* via `future.v3_singleFetch` and returning raw objects. This method will be
* removed in React Router v7. If you need to return a JSON Response, you can
* use `Response.json()`.
*
* @see https://remix.run/utils/json
*/
export const json: JsonFunction = (data, init = {}) => {
Expand All @@ -50,6 +55,10 @@ export const json: JsonFunction = (data, init = {}) => {
/**
* This is a shortcut for creating Remix deferred responses
*
* @deprecated This utility is deprecated in favor of opting into Single Fetch
* via `future.v3_singleFetch` and returning raw objects. This method will be
* removed in React Router v7.
*
* @see https://remix.run/utils/defer
*/
export const defer: DeferFunction = (data, init = {}) => {
Expand Down
Loading