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

Turn on Remix v3_singleFetch future flag #2708

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 2 additions & 4 deletions docs/preview/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {json, type LinksFunction} from '@remix-run/node';
import {type LinksFunction} from '@remix-run/node';
import {
Links,
Meta,
Expand Down Expand Up @@ -26,9 +26,7 @@ export async function loader() {
}
}

return json({
data,
});
return {data};
}

export default function App() {
Expand Down
2 changes: 1 addition & 1 deletion docs/preview/app/routes/$doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter';
import {oneDark} from 'react-syntax-highlighter/dist/cjs/styles/prism/index.js';

export async function loader({params}: LoaderFunctionArgs) {
return json({doc: params.doc});
return {doc: params.doc};
}

function getDefinition(definitions: any, type: string) {
Expand Down
1 change: 1 addition & 0 deletions docs/preview/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
v3_fetcherPersist: false,
v3_relativeSplatPath: false,
v3_throwAbortReason: false,
v3_singleFetch: true,
},
}),
tsconfigPaths(),
Expand Down
2 changes: 1 addition & 1 deletion docs/shopify-dev/analytics-setup/js/app/entry-server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function handleRequest(

const body = await renderToReadableStream(
<NonceProvider>
<RemixServer context={remixContext} url={request.url} />
<RemixServer context={remixContext} url={request.url} nonce={nonce} />
</NonceProvider>,
{
nonce,
Expand Down
5 changes: 2 additions & 3 deletions docs/shopify-dev/analytics-setup/js/app/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Analytics,
// [END import]
} from '@shopify/hydrogen';
import {defer} from '@shopify/remix-oxygen';
import {
Links,
Meta,
Expand Down Expand Up @@ -83,7 +82,7 @@ export async function loader(args) {
const {storefront, env} = args.context;
// [END env]

return defer({
return {
...deferredData,
...criticalData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
Expand All @@ -103,7 +102,7 @@ export async function loader(args) {
language: args.context.storefront.i18n.language,
},
// [END consent]
});
};
}

/**
Expand Down
6 changes: 3 additions & 3 deletions docs/shopify-dev/analytics-setup/js/app/routes/cart.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useLoaderData} from '@remix-run/react';
import {CartForm, Analytics} from '@shopify/hydrogen';
import {json} from '@shopify/remix-oxygen';
import {data} from '@shopify/remix-oxygen';
import {CartMain} from '~/components/CartMain';

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function action({request, context}) {
headers.set('Location', redirectTo);
}

return json(
return data(
{
cart: cartResult,
errors,
Expand All @@ -99,7 +99,7 @@ export async function action({request, context}) {
*/
export async function loader({context}) {
const {cart} = context;
return json(await cart.get());
return await cart.get();
}

export default function Cart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function loader(args) {
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

return defer({...deferredData, ...criticalData});
return {...deferredData, ...criticalData};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function loader(args) {
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

return defer({...deferredData, ...criticalData});
return {...deferredData, ...criticalData};
}

/**
Expand Down
3 changes: 1 addition & 2 deletions docs/shopify-dev/analytics-setup/js/app/routes/search.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {json} from '@shopify/remix-oxygen';
import {useLoaderData} from '@remix-run/react';
import {getPaginationVariables, Analytics} from '@shopify/hydrogen';
import {SearchForm} from '~/components/SearchForm';
Expand Down Expand Up @@ -27,7 +26,7 @@ export async function loader({request, context}) {
return {term: '', result: null, error: error.message};
});

return json(await searchPromise);
return await searchPromise;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/shopify-dev/analytics-setup/ts/app/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function handleRequest(

const body = await renderToReadableStream(
<NonceProvider>
<RemixServer context={remixContext} url={request.url} />
<RemixServer context={remixContext} url={request.url} nonce={nonce} />
</NonceProvider>,
{
nonce,
Expand Down
6 changes: 3 additions & 3 deletions docs/shopify-dev/analytics-setup/ts/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Analytics,
// [END import]
} from '@shopify/hydrogen';
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {
Links,
Meta,
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function loader(args: LoaderFunctionArgs) {
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

return defer({
return {
...deferredData,
...criticalData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
Expand All @@ -103,7 +103,7 @@ export async function loader(args: LoaderFunctionArgs) {
language: storefront.i18n.language,
},
// [END consent]
});
};
}

/**
Expand Down
6 changes: 3 additions & 3 deletions docs/shopify-dev/analytics-setup/ts/app/routes/cart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type MetaFunction, useLoaderData} from '@remix-run/react';
import type {CartQueryDataReturn} from '@shopify/hydrogen';
import {CartForm, Analytics} from '@shopify/hydrogen';
import {json, type LoaderFunctionArgs, type ActionFunctionArgs} from '@shopify/remix-oxygen';
import {data, type LoaderFunctionArgs, type ActionFunctionArgs} from '@shopify/remix-oxygen';
import {CartMain} from '~/components/CartMain';

export const meta: MetaFunction = () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function action({request, context}: ActionFunctionArgs) {
headers.set('Location', redirectTo);
}

return json(
return data(
{
cart: cartResult,
errors,
Expand All @@ -95,7 +95,7 @@ export async function action({request, context}: ActionFunctionArgs) {

export async function loader({context}: LoaderFunctionArgs) {
const {cart} = context;
return json(await cart.get());
return await cart.get();
}

export default function Cart() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defer, redirect, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {redirect, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {useLoaderData, Link, type MetaFunction} from '@remix-run/react';
import {
getPaginationVariables,
Expand All @@ -21,7 +21,7 @@ export async function loader(args: LoaderFunctionArgs) {
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

return defer({...deferredData, ...criticalData});
return {...deferredData, ...criticalData};
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {useLoaderData, type MetaFunction} from '@remix-run/react';
import type {ProductFragment} from 'storefrontapi.generated';
import {
getSelectedProductOptions,
// [START import]
Expand All @@ -11,8 +10,6 @@ import {
getAdjacentAndFirstAvailableVariants,
useSelectedOptionInUrlParam,
} from '@shopify/hydrogen';
import type {SelectedOption} from '@shopify/hydrogen/storefront-api-types';
import {getVariantUrl} from '~/lib/variants';
import {ProductPrice} from '~/components/ProductPrice';
import {ProductImage} from '~/components/ProductImage';
import {ProductForm} from '~/components/ProductForm';
Expand All @@ -28,7 +25,7 @@ export async function loader(args: LoaderFunctionArgs) {
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

return defer({...deferredData, ...criticalData});
return {...deferredData, ...criticalData};
}

/**
Expand Down
3 changes: 1 addition & 2 deletions docs/shopify-dev/analytics-setup/ts/app/routes/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
json,
type LoaderFunctionArgs,
type ActionFunctionArgs,
} from '@shopify/remix-oxygen';
Expand Down Expand Up @@ -29,7 +28,7 @@ export async function loader({request, context}: LoaderFunctionArgs) {
return {term: '', result: null, error: error.message};
});

return json(await searchPromise);
return await searchPromise;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions examples/b2b/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useNonce, getShopAnalytics, Analytics} from '@shopify/hydrogen';
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {
Links,
Meta,
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function loader({context}: LoaderFunctionArgs) {
},
});

return defer({
return {
cart: cartPromise,
footer: footerPromise,
header: await headerPromise,
Expand All @@ -137,7 +137,7 @@ export async function loader({context}: LoaderFunctionArgs) {
country: context.storefront.i18n.country,
language: context.storefront.i18n.language,
},
});
};
}

export function Layout({children}: {children?: React.ReactNode}) {
Expand Down
4 changes: 2 additions & 2 deletions examples/b2b/app/routes/b2blocations.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {useLoaderData} from '@remix-run/react';
import {B2BLocationSelector} from '../components/B2BLocationSelector';
import {CUSTOMER_LOCATIONS_QUERY} from '~/graphql/customer-account/CustomerLocationsQuery';
Expand Down Expand Up @@ -30,7 +30,7 @@ export async function loader({context}: LoaderFunctionArgs) {

const modalOpen = Boolean(company) && !companyLocationId;

return defer({company, companyLocationId, modalOpen});
return {company, companyLocationId, modalOpen};
}

export default function CartRoute() {
Expand Down
4 changes: 2 additions & 2 deletions examples/b2b/app/routes/products.$handle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {useLoaderData, type MetaFunction} from '@remix-run/react';
import {
getSelectedProductOptions,
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function loader(args: LoaderFunctionArgs) {
/********** EXAMPLE UPDATE END *************/
/***********************************************/

return defer({...deferredData, ...criticalData});
return {...deferredData, ...criticalData};
}

/**
Expand Down
3 changes: 2 additions & 1 deletion examples/b2b/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"./**/*.d.ts",
"./**/*.ts",
"./**/*.tsx",
"../../templates/skeleton/*.d.ts"
"../../templates/skeleton/*.d.ts",
"../../templates/skeleton/vite.config.ts"
],
"compilerOptions": {
"baseUrl": ".",
Expand Down
6 changes: 3 additions & 3 deletions examples/classic-remix/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useNonce, getShopAnalytics, Analytics} from '@shopify/hydrogen';
import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {
Links,
Meta,
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function loader(args: LoaderFunctionArgs) {

const {storefront, env} = args.context;

return defer({
return {
...criticalData,
...deferredData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
Expand All @@ -84,7 +84,7 @@ export async function loader(args: LoaderFunctionArgs) {
checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
},
});
};
}

/**
Expand Down
1 change: 1 addition & 0 deletions examples/classic-remix/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
v3_relativeSplatpath: true,
v3_throwAbortReason: true,
v3_lazyRouteDiscovery: true,
v3_singleFetch: true,
},
};
2 changes: 1 addition & 1 deletion examples/classic-remix/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../templates/skeleton/tsconfig.json",
"include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx"],
"include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx", "../../templates/skeleton/vite.config.ts"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
Expand Down
6 changes: 3 additions & 3 deletions examples/custom-cart-method/app/routes/cart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type MetaFunction, useLoaderData} from '@remix-run/react';
import type {CartQueryDataReturn} from '@shopify/hydrogen';
import {CartForm} from '@shopify/hydrogen';
import {json, type LoaderFunctionArgs, type ActionFunctionArgs} from '@shopify/remix-oxygen';
import {data, type LoaderFunctionArgs, type ActionFunctionArgs} from '@shopify/remix-oxygen';
import type {
SelectedOptionInput,
CartLineUpdateInput,
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function action({request, context}: ActionFunctionArgs) {
headers.set('Location', redirectTo);
}

return json(
return data(
{
cart: cartResult,
errors,
Expand All @@ -117,7 +117,7 @@ export async function action({request, context}: ActionFunctionArgs) {

export async function loader({context}: LoaderFunctionArgs) {
const {cart} = context;
return json(await cart.get());
return await cart.get();
}

export default function Cart() {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom-cart-method/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"./**/*.d.ts",
"./**/*.ts",
"./**/*.tsx",
"../../templates/skeleton/*.d.ts"
"../../templates/skeleton/*.d.ts",
"../../templates/skeleton/vite.config.ts"
],
"compilerOptions": {
"baseUrl": ".",
Expand Down
Loading
Loading