From 4a9f98f4bca0493fbcca3160d60fdc9461c9812e Mon Sep 17 00:00:00 2001 From: Michelle Chen Date: Mon, 13 May 2024 14:08:36 -0400 Subject: [PATCH] turn on single fetch feature flag & make single fetch works remove any defer & json loader or action return remove all of redirect not sure how to solve these ... replace UIMatch remove deprecate methods from remix-oxygen change new Response in loader/action to use response arg instead remove question mark from response when it is coming from defineLoader/defineAction, also use headers.set when its right before the return fix CSP with Inline Scripts fix search type with loader type update cart utility and put response into options update customerAccount client to use response to set session header fix redirect in loader (resource route), ensure to return a Response instead of manipulating the response object get positive flow working. Looks like action & loader works slightly differently run codemod on skeleton resource route, return response object instead add nativeFetch fully use ResponseStub get rid of session.helper revert to response object return revert Hydrogen package use Response Object for utilities and ResponseStub for skeleton template add cf compat flag --- packages/hydrogen/src/customer/customer.ts | 4 +- packages/mini-oxygen/src/common/compat.ts | 5 +- templates/skeleton/app/components/Footer.tsx | 45 +++++--- templates/skeleton/app/components/Header.tsx | 24 +++-- templates/skeleton/app/components/Layout.tsx | 46 ++++---- templates/skeleton/app/entry.server.tsx | 2 +- templates/skeleton/app/lib/root-data.ts | 11 -- templates/skeleton/app/root.tsx | 67 +++++------- templates/skeleton/app/routes/$.tsx | 7 +- .../skeleton/app/routes/[robots.txt].tsx | 14 +-- .../skeleton/app/routes/[sitemap.xml].tsx | 14 ++- templates/skeleton/app/routes/_index.tsx | 4 +- templates/skeleton/app/routes/account.$.tsx | 12 ++- .../skeleton/app/routes/account._index.tsx | 12 ++- .../skeleton/app/routes/account.addresses.tsx | 102 +++++------------- .../app/routes/account.orders.$id.tsx | 18 ++-- .../app/routes/account.orders._index.tsx | 4 +- .../skeleton/app/routes/account.profile.tsx | 21 ++-- templates/skeleton/app/routes/account.tsx | 14 +-- .../skeleton/app/routes/account_.logout.tsx | 11 +- .../app/routes/api.predictive-search.tsx | 18 +++- .../blogs.$blogHandle.$articleHandle.tsx | 12 ++- .../app/routes/blogs.$blogHandle._index.tsx | 11 +- .../skeleton/app/routes/blogs._index.tsx | 4 +- templates/skeleton/app/routes/cart.$lines.tsx | 27 +++-- templates/skeleton/app/routes/cart.tsx | 49 +++++---- .../app/routes/collections.$handle.tsx | 26 +++-- .../app/routes/collections._index.tsx | 4 +- .../skeleton/app/routes/collections.all.tsx | 4 +- .../skeleton/app/routes/discount.$code.tsx | 20 ++-- .../skeleton/app/routes/pages.$handle.tsx | 9 +- .../skeleton/app/routes/policies.$handle.tsx | 12 ++- .../skeleton/app/routes/policies._index.tsx | 9 +- .../skeleton/app/routes/products.$handle.tsx | 27 +++-- templates/skeleton/app/routes/search.tsx | 6 +- templates/skeleton/server.ts | 4 - templates/skeleton/tsconfig.json | 5 +- templates/skeleton/vite.config.ts | 4 + 38 files changed, 356 insertions(+), 332 deletions(-) delete mode 100644 templates/skeleton/app/lib/root-data.ts diff --git a/packages/hydrogen/src/customer/customer.ts b/packages/hydrogen/src/customer/customer.ts index 25a6e0971f..0a49f1dbe9 100644 --- a/packages/hydrogen/src/customer/customer.ts +++ b/packages/hydrogen/src/customer/customer.ts @@ -60,7 +60,9 @@ function defaultAuthStatusHandler(request: CrossRuntimeRequest) { const redirectTo = DEFAULT_LOGIN_URL + - `?${new URLSearchParams({return_to: pathname}).toString()}`; + `?${new URLSearchParams({ + return_to: pathname.replace(/\.data$/, ''), // for single fetch + }).toString()}`; return redirect(redirectTo); } diff --git a/packages/mini-oxygen/src/common/compat.ts b/packages/mini-oxygen/src/common/compat.ts index 390f112014..d4835a2c98 100644 --- a/packages/mini-oxygen/src/common/compat.ts +++ b/packages/mini-oxygen/src/common/compat.ts @@ -1,4 +1,7 @@ export const OXYGEN_COMPAT_PARAMS = { - compatibilityFlags: ['streams_enable_constructors' as const], + compatibilityFlags: [ + 'streams_enable_constructors' as const, + 'http_headers_getsetcookie' as any, + ], compatibilityDate: '2022-10-31' as const, }; diff --git a/templates/skeleton/app/components/Footer.tsx b/templates/skeleton/app/components/Footer.tsx index 001742f659..f9494d328f 100644 --- a/templates/skeleton/app/components/Footer.tsx +++ b/templates/skeleton/app/components/Footer.tsx @@ -1,29 +1,46 @@ -import {NavLink} from '@remix-run/react'; +import {Await, NavLink} from '@remix-run/react'; +import {Suspense} from 'react'; import type {FooterQuery, HeaderQuery} from 'storefrontapi.generated'; -import {useRootLoaderData} from '~/lib/root-data'; + +interface FooterProps { + footer: Promise; + header: HeaderQuery; + publicStoreDomain: string; +} export function Footer({ - menu, - shop, -}: FooterQuery & {shop: HeaderQuery['shop']}) { + footer: footerPromise, + header, + publicStoreDomain, +}: FooterProps) { return ( -
- {menu && shop?.primaryDomain?.url && ( - - )} -
+ + + {(footer) => ( +
+ {footer.menu && header.shop.primaryDomain?.url && ( + + )} +
+ )} +
+
); } function FooterMenu({ menu, primaryDomainUrl, + publicStoreDomain, }: { - menu: FooterQuery['menu']; - primaryDomainUrl: HeaderQuery['shop']['primaryDomain']['url']; + menu: Awaited['menu']; + primaryDomainUrl: FooterProps['header']['shop']['primaryDomain']['url']; + publicStoreDomain: string; }) { - const {publicStoreDomain} = useRootLoaderData(); - return (