Turn on Remix v3_singleFetch future flag#2708
Merged
Merged
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
This comment has been minimized.
This comment has been minimized.
liady
approved these changes
Jan 15, 2025
rbshop
reviewed
Jan 15, 2025
Comment on lines
+62
to
+74
| /** | ||
| * Remix (single-fetch) request objects have different url | ||
| * paths when soft navigating. Examples: | ||
| * | ||
| * /_root.data - home page | ||
| * /collections.data - collections page | ||
| * | ||
| * These url annotations needs to be cleaned up before constructing urls to be passed as | ||
| * GET parameters for customer login url | ||
| */ | ||
| const cleanedPathname = pathname | ||
| .replace(/\.data$/, '') | ||
| .replace(/^\/_root$/, '/'); |
Contributor
There was a problem hiding this comment.
Is this new behaviour covered in any of our tests?
Author
There was a problem hiding this comment.
oh good catch - I'll get a test in
rbshop
reviewed
Jan 15, 2025
rbshop
reviewed
Jan 15, 2025
Co-authored-by: Rheese <110670476+rbshop@users.noreply.github.com>
rbshop
approved these changes
Jan 15, 2025
added 11 commits
January 17, 2025 15:05
juanpprieto
approved these changes
Feb 6, 2025
juanpprieto
left a comment
Contributor
There was a problem hiding this comment.
Looks great, thanks Helen. Tested skeleton and all good
Merged
juanpprieto
pushed a commit
that referenced
this pull request
Sep 17, 2025
Co-authored-by: Rheese <110670476+rbshop@users.noreply.github.com>
frandiox
pushed a commit
that referenced
this pull request
Jun 16, 2026
Co-authored-by: Rheese <110670476+rbshop@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
Turn on Remix
v3_singleFetchfuture flagUpgrade steps
Remix single fetch migration quick guide: https://remix.run/docs/en/main/start/future-flags#v3_singlefetch
Remix single fetch migration guide: https://remix.run/docs/en/main/guides/single-fetch
Note: If you have any routes that appends (or looks for) a search param named
_data, make sure to rename it to something else.In your
vite.config.ts, add the single fetch future flag.In your
entry.server.tsx, addnonceto the<RemixServer>.const body = await renderToReadableStream( <NonceProvider> <RemixServer context={remixContext} url={request.url} + nonce={nonce} /> </NonceProvider>,Update the
shouldRevalidatefunction inroot.tsx.Defaulting to no revalidation for root loader data to improve performance. When using this feature, you risk your UI getting out of sync with your server. Use with caution. If you are uncomfortable with this optimization, update the
return false;toreturn defaultShouldRevalidate;instead.For more details see: https://remix.run/docs/en/main/route/should-revalidate
export const shouldRevalidate: ShouldRevalidateFunction = ({ formMethod, currentUrl, nextUrl, - defaultShouldRevalidate, }) => { // revalidate when a mutation is performed e.g add to cart, login... if (formMethod && formMethod !== 'GET') return true; // revalidate when manually revalidating via useRevalidator if (currentUrl.toString() === nextUrl.toString()) return true; - return defaultShouldRevalidate; + return false; };Update
cart.tsxto add a headers export and update todataimport usage.import { - json, + data, type LoaderFunctionArgs, type ActionFunctionArgs, type HeadersFunction } from '@shopify/remix-oxygen'; + export const headers: HeadersFunction = ({ actionHeaders }) => actionHeaders; export async function action({request, context}: ActionFunctionArgs) { ... - return json( + return data( { cart: cartResult, errors, warnings, analytics: { cartId, }, }, {status, headers}, ); } export async function loader({context}: LoaderFunctionArgs) { const {cart} = context; - return json(await cart.get()); + return await cart.get(); }Deprecate
jsonanddeferimport usage from@shopify/remix-oxygenRemove
json()/defer()in favor of raw objects.Single Fetch supports JSON objects and Promises out of the box, so you can return the raw data from your loader/action functions:
If you were using the second parameter of json/defer to set a custom status or headers on your response, you can continue doing so via the new data API:
If you are using legacy customer account flow or multipass, there are a couple more files that requires updating:
In
root.tsxandroutes/account.tsx, add aheadersexport forloaderHeaders.+ export const headers: HeadersFunction = ({loaderHeaders}) => loaderHeaders;In
routes/account_.register.tsx, add aheadersexport foractionHeaders.+ export const headers: HeadersFunction = ({actionHeaders}) => actionHeaders;If you are using multipass, in
routes/account_.login.multipass.tsxa. export a
headersexport+ export const headers: HeadersFunction = ({actionHeaders}) => actionHeaders;b. Update all
jsonresponse wrapper toremixDataimport { - json, + data as remixData, } from '@shopify/remix-oxygen'; - return json( + return remixData( ... );WHAT is this pull request doing?
For all templates, remove
json(), anddefer()Remix response functions and usedata()Remix response function when requiredHOW to test your changes?
Make sure all templates are working properly without errors across all functions. Make sure:
Post-merge steps
Checklist