-
Notifications
You must be signed in to change notification settings - Fork 301
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
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
This comment has been minimized.
This comment has been minimized.
/** | ||
* 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$/, '/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new behaviour covered in any of our tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good catch - I'll get a test in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks Helen. Tested skeleton and all good
WHY are these changes introduced?
Turn on Remix
v3_singleFetch
future 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
, addnonce
to the<RemixServer>
.const body = await renderToReadableStream( <NonceProvider> <RemixServer context={remixContext} url={request.url} + nonce={nonce} /> </NonceProvider>,
Update the
shouldRevalidate
function 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
Update
cart.tsx
to add a headers export and update todata
import usage.Deprecate
json
anddefer
import usage from@shopify/remix-oxygen
Remove
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.tsx
androutes/account.tsx
, add aheaders
export forloaderHeaders
.+ export const headers: HeadersFunction = ({loaderHeaders}) => loaderHeaders;
In
routes/account_.register.tsx
, add aheaders
export foractionHeaders
.+ export const headers: HeadersFunction = ({actionHeaders}) => actionHeaders;
If you are using multipass, in
routes/account_.login.multipass.tsx
a. export a
headers
export+ export const headers: HeadersFunction = ({actionHeaders}) => actionHeaders;
b. Update all
json
response wrapper toremixData
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