@shopify/hydrogen 0.11.0-experimental.1 → 0.11.1-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +504 -0
- package/dist/esnext/client.d.ts +1 -1
- package/dist/esnext/client.js +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +11 -2
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +2 -2
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +1 -1
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +2 -2
- package/dist/esnext/components/CartProvider/CartProvider.client.js +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.js +2 -2
- package/dist/esnext/components/Image/Image.d.ts +1 -1
- package/dist/esnext/components/Image/Image.js +9 -9
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +13 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -3
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +8 -6
- package/dist/esnext/components/MediaFile/MediaFile.js +6 -6
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +16 -16
- package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +1 -1
- package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/Money/Money.client.js +2 -2
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +3 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +21 -4
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +5 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +30 -9
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.d.ts +8 -0
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +12 -0
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +8 -7
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +9 -35
- package/dist/esnext/components/ProductProvider/context.d.ts +10 -6
- package/dist/esnext/components/ProductProvider/context.js +1 -0
- package/dist/esnext/components/Seo/DefaultPageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/DescriptionSeo.client.js +2 -2
- package/dist/esnext/components/Seo/HomePageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ImageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ProductSeo.client.js +5 -3
- package/dist/esnext/components/Seo/TitleSeo.client.js +2 -2
- package/dist/esnext/components/Seo/TwitterSeo.client.js +2 -2
- package/dist/esnext/components/Seo/types.d.ts +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -2
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +3 -3
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/Video/Video.js +3 -3
- package/dist/esnext/components/index.d.ts +0 -8
- package/dist/esnext/components/index.js +0 -8
- package/dist/esnext/entry-client.js +1 -1
- package/dist/esnext/entry-server.d.ts +18 -2
- package/dist/esnext/entry-server.js +347 -329
- package/dist/esnext/foundation/Head/Head.client.d.ts +5 -0
- package/dist/esnext/foundation/Head/Head.client.js +10 -0
- package/dist/esnext/foundation/Head/index.d.ts +1 -0
- package/dist/esnext/foundation/Head/index.js +1 -0
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -1
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +43 -4
- package/dist/esnext/foundation/useQuery/hooks.d.ts +11 -3
- package/dist/esnext/foundation/useQuery/hooks.js +21 -5
- package/dist/esnext/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/esnext/framework/CachingStrategy/index.js +96 -0
- package/dist/esnext/framework/Hydration/Html.js +5 -12
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +51 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/esnext/framework/cache/in-memory.js +6 -5
- package/dist/esnext/framework/cache.d.ts +3 -3
- package/dist/esnext/framework/cache.js +4 -18
- package/dist/esnext/framework/middleware.d.ts +7 -7
- package/dist/esnext/framework/middleware.js +15 -43
- package/dist/esnext/framework/plugin.js +14 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +38 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.js +37 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -1
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +70 -0
- package/dist/esnext/hooks/useProduct/useProduct.d.ts +150 -1
- package/dist/esnext/hooks/useProduct/useProduct.js +36 -3
- package/dist/esnext/hooks/useProductOptions/types.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +6 -6
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +11 -4
- package/dist/esnext/hooks/useShopQuery/hooks.js +6 -3
- package/dist/esnext/index.d.ts +2 -1
- package/dist/esnext/index.js +2 -1
- package/dist/esnext/platforms/node.d.ts +10 -0
- package/dist/esnext/platforms/node.js +38 -0
- package/dist/esnext/platforms/worker-event.d.ts +9 -0
- package/dist/esnext/platforms/worker-event.js +24 -0
- package/dist/esnext/streaming.server.d.ts +17 -7
- package/dist/esnext/streaming.server.js +44 -0
- package/dist/esnext/types.d.ts +25 -25
- package/dist/esnext/utilities/apiRoutes.d.ts +1 -2
- package/dist/esnext/utilities/apiRoutes.js +4 -3
- package/dist/esnext/utilities/bot-ua.d.ts +4 -0
- package/dist/esnext/utilities/bot-ua.js +54 -0
- package/dist/esnext/utilities/fetch.js +1 -26
- package/dist/esnext/utilities/log/index.d.ts +4 -1
- package/dist/esnext/utilities/log/index.js +4 -1
- package/dist/esnext/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/esnext/utilities/log/log-cache-api-status.js +9 -0
- package/dist/esnext/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/esnext/utilities/log/log-cache-header.js +30 -0
- package/dist/esnext/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/esnext/utilities/log/log-query-timeline.js +83 -0
- package/dist/esnext/utilities/log/log.d.ts +11 -8
- package/dist/esnext/utilities/log/log.js +24 -35
- package/dist/esnext/utilities/log/utils.d.ts +3 -0
- package/dist/esnext/utilities/log/utils.js +13 -0
- package/dist/esnext/utilities/template.d.ts +9 -0
- package/dist/esnext/utilities/template.js +23 -0
- package/dist/{worker/foundation/ShopifyProvider/types.js → esnext/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/esnext/utilities/web-api-polyfill.js +19 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/entry-server.d.ts +22 -0
- package/dist/node/entry-server.js +581 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +23 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +132 -0
- package/dist/node/foundation/ServerRequestProvider/index.d.ts +1 -0
- package/dist/node/foundation/ServerRequestProvider/index.js +13 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +25 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.js +68 -0
- package/dist/node/foundation/ServerStateProvider/index.d.ts +2 -0
- package/dist/node/foundation/ServerStateProvider/index.js +6 -0
- package/dist/node/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/node/framework/CachingStrategy/index.js +108 -0
- package/dist/node/framework/Hydration/Html.js +5 -12
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +50 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/node/framework/cache/in-memory.js +6 -5
- package/dist/node/framework/cache.d.ts +3 -3
- package/dist/node/framework/cache.js +6 -20
- package/dist/node/framework/middleware.d.ts +7 -7
- package/dist/node/framework/middleware.js +14 -46
- package/dist/node/framework/plugin.js +33 -3
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +43 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.js +39 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +4 -1
- package/dist/node/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +75 -0
- package/dist/node/streaming.server.d.ts +21 -0
- package/dist/node/streaming.server.js +59 -0
- package/dist/node/types.d.ts +25 -25
- package/dist/node/utilities/apiRoutes.d.ts +1 -2
- package/dist/node/utilities/apiRoutes.js +4 -3
- package/dist/node/utilities/bot-ua.d.ts +4 -0
- package/dist/node/utilities/bot-ua.js +58 -0
- package/dist/node/utilities/defer.d.ts +6 -0
- package/dist/node/utilities/defer.js +18 -0
- package/dist/node/utilities/error.d.ts +1 -0
- package/dist/node/utilities/error.js +10 -0
- package/dist/node/utilities/log/index.d.ts +4 -0
- package/dist/node/utilities/log/index.js +18 -0
- package/dist/node/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/node/utilities/log/log-cache-api-status.js +13 -0
- package/dist/node/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/node/utilities/log/log-cache-header.js +35 -0
- package/dist/node/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/node/utilities/log/log-query-timeline.js +88 -0
- package/dist/node/utilities/log/log.d.ts +11 -8
- package/dist/node/utilities/log/log.js +27 -37
- package/dist/node/utilities/log/utils.d.ts +3 -0
- package/dist/node/utilities/log/utils.js +18 -0
- package/dist/node/utilities/template.d.ts +9 -0
- package/dist/node/utilities/template.js +27 -0
- package/dist/{worker/types.js → node/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/node/utilities/web-api-polyfill.js +43 -0
- package/package.json +20 -10
- package/web-polyfills.js +1 -0
- package/LICENSE.md +0 -7
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.d.ts +0 -22
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.js +0 -13
- package/dist/esnext/components/CartLineAttributes/index.d.ts +0 -1
- package/dist/esnext/components/CartLineAttributes/index.js +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.d.ts +0 -21
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.js +0 -13
- package/dist/esnext/components/CartLineSelectedOptions/index.d.ts +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/index.js +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +0 -11
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +0 -17
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.d.ts +0 -9
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +0 -17
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.d.ts +0 -10
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.js +0 -16
- package/dist/esnext/components/SelectedVariantImage/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantImage/index.js +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +0 -15
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +0 -24
- package/dist/esnext/components/SelectedVariantMetafield/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/index.js +0 -1
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.d.ts +0 -12
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.js +0 -22
- package/dist/esnext/components/SelectedVariantPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantPrice/index.js +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.d.ts +0 -8
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.js +0 -18
- package/dist/esnext/components/SelectedVariantShopPayButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.d.ts +0 -7
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.js +0 -16
- package/dist/esnext/components/SelectedVariantUnitPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/index.js +0 -1
- package/dist/esnext/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/esnext/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/esnext/foundation/Helmet/index.d.ts +0 -1
- package/dist/esnext/foundation/Helmet/index.js +0 -1
- package/dist/esnext/handle-event.d.ts +0 -23
- package/dist/esnext/handle-event.js +0 -132
- package/dist/esnext/handle-worker-event.d.ts +0 -11
- package/dist/esnext/handle-worker-event.js +0 -14
- package/dist/node/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/node/foundation/Helmet/Helmet.client.js +0 -17
- package/dist/node/foundation/Helmet/index.d.ts +0 -1
- package/dist/node/foundation/Helmet/index.js +0 -5
- package/dist/node/foundation/ssr-interop.d.ts +0 -29
- package/dist/node/foundation/ssr-interop.js +0 -39
- package/dist/node/handle-event.d.ts +0 -23
- package/dist/node/handle-event.js +0 -135
- package/dist/worker/constants.d.ts +0 -1
- package/dist/worker/constants.js +0 -1
- package/dist/worker/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/worker/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/worker/foundation/Helmet/index.d.ts +0 -1
- package/dist/worker/foundation/Helmet/index.js +0 -1
- package/dist/worker/foundation/ShopifyProvider/types.d.ts +0 -15
- package/dist/worker/foundation/ssr-interop.d.ts +0 -29
- package/dist/worker/foundation/ssr-interop.js +0 -35
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.d.ts +0 -23
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.js +0 -57
- package/dist/worker/framework/config.d.ts +0 -6
- package/dist/worker/framework/config.js +0 -6
- package/dist/worker/framework/runtime.d.ts +0 -13
- package/dist/worker/framework/runtime.js +0 -27
- package/dist/worker/graphql/types/types.d.ts +0 -5761
- package/dist/worker/graphql/types/types.js +0 -1436
- package/dist/worker/handle-event.d.ts +0 -23
- package/dist/worker/handle-event.js +0 -132
- package/dist/worker/handle-worker-event.d.ts +0 -11
- package/dist/worker/handle-worker-event.js +0 -14
- package/dist/worker/types.d.ts +0 -96
- package/dist/worker/utilities/apiRoutes.d.ts +0 -21
- package/dist/worker/utilities/apiRoutes.js +0 -87
- package/dist/worker/utilities/log/log.d.ts +0 -18
- package/dist/worker/utilities/log/log.js +0 -77
- package/dist/worker/utilities/matchPath.d.ts +0 -10
- package/dist/worker/utilities/matchPath.js +0 -54
- package/dist/worker/utilities/timing.d.ts +0 -7
- package/dist/worker/utilities/timing.js +0 -14
- package/worker.js +0 -1
package/dist/esnext/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export * from './foundation/';
|
|
|
2
2
|
export * from './components/';
|
|
3
3
|
export * from './hooks/';
|
|
4
4
|
export { flattenConnection, fetchBuilder, graphqlRequestBody, decodeShopifyId, isClient, getTime, } from './utilities';
|
|
5
|
-
export { log, setLogger } from './utilities/log';
|
|
5
|
+
export { log, setLogger, setLoggerOptions } from './utilities/log';
|
|
6
6
|
// This is exported here because it contains a Server Component
|
|
7
7
|
export { LocalizationProvider } from './components/LocalizationProvider/LocalizationProvider.server';
|
|
8
8
|
// Exported here because users shouldn't be making `useShopQuery` calls from the client
|
|
@@ -10,3 +10,4 @@ export * from './hooks/useShopQuery';
|
|
|
10
10
|
// Export server-only CartQuery here instead of `CartProvider.client` to prevent
|
|
11
11
|
// it from being bundled with other client components
|
|
12
12
|
export { CartQuery } from './graphql/graphql-constants';
|
|
13
|
+
export { generateCacheControlHeader, NoStore, CacheSeconds, CacheMinutes, CacheHours, CacheDays, CacheWeeks, CacheMonths, CacheCustom, } from './framework/CachingStrategy';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import '../utilities/web-api-polyfill';
|
|
2
|
+
import connect from 'connect';
|
|
3
|
+
declare type CreateServerOptions = {
|
|
4
|
+
port?: number | string;
|
|
5
|
+
};
|
|
6
|
+
export declare function createServer({ port, }?: CreateServerOptions): Promise<{
|
|
7
|
+
app: connect.Server;
|
|
8
|
+
port: string | number;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import '../utilities/web-api-polyfill';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
// eslint-disable-next-line node/no-missing-import
|
|
5
|
+
import entrypoint from '__SERVER_ENTRY__';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
// eslint-disable-next-line node/no-missing-import
|
|
8
|
+
import indexTemplate from '__INDEX_TEMPLATE__?raw';
|
|
9
|
+
import { hydrogenMiddleware } from '../framework/middleware';
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import serveStatic from 'serve-static';
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import compression from 'compression';
|
|
14
|
+
import bodyParser from 'body-parser';
|
|
15
|
+
import connect from 'connect';
|
|
16
|
+
const handleRequest = entrypoint;
|
|
17
|
+
export async function createServer({ port = process.env.PORT || 8080, } = {}) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
globalThis.Oxygen = { env: process.env };
|
|
20
|
+
const app = connect();
|
|
21
|
+
app.use(compression());
|
|
22
|
+
app.use(serveStatic(path.resolve(__dirname, '../client'), {
|
|
23
|
+
index: false,
|
|
24
|
+
}));
|
|
25
|
+
app.use(bodyParser.raw({ type: '*/*' }));
|
|
26
|
+
app.use(hydrogenMiddleware({
|
|
27
|
+
getServerEntrypoint: () => handleRequest,
|
|
28
|
+
indexTemplate,
|
|
29
|
+
}));
|
|
30
|
+
return { app, port };
|
|
31
|
+
}
|
|
32
|
+
if (require.main === module) {
|
|
33
|
+
createServer().then(({ app, port }) => {
|
|
34
|
+
app.listen(port, () => {
|
|
35
|
+
console.log(`Hydrogen server running at http://localhost:${port}`);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
// eslint-disable-next-line node/no-missing-import
|
|
3
|
+
import entrypoint from '__SERVER_ENTRY__';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
// eslint-disable-next-line node/no-missing-import
|
|
6
|
+
import indexTemplate from '__INDEX_TEMPLATE__?raw';
|
|
7
|
+
const handleRequest = entrypoint;
|
|
8
|
+
if (!globalThis.Oxygen) {
|
|
9
|
+
globalThis.Oxygen = { env: globalThis };
|
|
10
|
+
}
|
|
11
|
+
async function handleEvent(event) {
|
|
12
|
+
try {
|
|
13
|
+
return (await handleRequest(event.request, {
|
|
14
|
+
indexTemplate,
|
|
15
|
+
cache: caches.default,
|
|
16
|
+
context: event,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return new Response(error.message || error.toString(), { status: 500 });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
addEventListener('fetch', (event) => event.respondWith(handleEvent(event)));
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import type { Writable } from 'stream';
|
|
1
2
|
export declare const rscRenderToReadableStream: (App: JSX.Element) => ReadableStream<Uint8Array>;
|
|
2
3
|
export declare const createFromReadableStream: (rs: ReadableStream<Uint8Array>) => {
|
|
3
4
|
readRoot: () => JSX.Element;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
declare type StreamOptions = {
|
|
7
|
+
nonce?: string;
|
|
8
|
+
onCompleteShell?: () => void;
|
|
9
|
+
onCompleteAll?: () => void;
|
|
10
|
+
onError?: (error: Error) => void;
|
|
11
|
+
bootstrapScripts?: string[];
|
|
12
|
+
bootstrapModules?: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare const ssrRenderToPipeableStream: (App: JSX.Element, options: StreamOptions) => {
|
|
15
|
+
pipe: Writable['pipe'];
|
|
16
|
+
};
|
|
17
|
+
export declare const ssrRenderToReadableStream: (App: JSX.Element, options: StreamOptions) => ReadableStream<Uint8Array>;
|
|
18
|
+
export declare function supportsReadableStream(): boolean;
|
|
19
|
+
export declare function isStreamingSupported(): Promise<boolean>;
|
|
20
|
+
export declare function bufferReadableStream(reader: ReadableStreamDefaultReader, cb?: (chunk: string) => void): Promise<string>;
|
|
21
|
+
export {};
|
|
@@ -12,3 +12,47 @@ export const rscRenderToReadableStream = _rscRenderToReadableStream;
|
|
|
12
12
|
export const createFromReadableStream = _createFromReadableStream;
|
|
13
13
|
export const ssrRenderToPipeableStream = _ssrRenderToPipeableStream;
|
|
14
14
|
export const ssrRenderToReadableStream = _ssrRenderToReadableStream;
|
|
15
|
+
export function supportsReadableStream() {
|
|
16
|
+
try {
|
|
17
|
+
new ReadableStream();
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch (_) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
let cachedStreamingSupport;
|
|
25
|
+
export async function isStreamingSupported() {
|
|
26
|
+
if (cachedStreamingSupport === undefined) {
|
|
27
|
+
try {
|
|
28
|
+
const rs = new ReadableStream({
|
|
29
|
+
start(controller) {
|
|
30
|
+
controller.close();
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
// This will throw in CFW until streaming
|
|
34
|
+
// is supported. It works in Miniflare.
|
|
35
|
+
await new Response(rs).text();
|
|
36
|
+
cachedStreamingSupport = true;
|
|
37
|
+
}
|
|
38
|
+
catch (_) {
|
|
39
|
+
cachedStreamingSupport = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return cachedStreamingSupport;
|
|
43
|
+
}
|
|
44
|
+
export async function bufferReadableStream(reader, cb) {
|
|
45
|
+
const decoder = new TextDecoder();
|
|
46
|
+
let result = '';
|
|
47
|
+
while (true) {
|
|
48
|
+
const { done, value } = await reader.read();
|
|
49
|
+
if (done)
|
|
50
|
+
break;
|
|
51
|
+
const stringValue = typeof value === 'string' ? value : decoder.decode(value);
|
|
52
|
+
result += stringValue;
|
|
53
|
+
if (cb) {
|
|
54
|
+
cb(stringValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
package/dist/esnext/types.d.ts
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ServerResponse } from 'http';
|
|
2
|
+
import type { ServerResponse } from 'http';
|
|
3
|
+
import type { Logger } from './utilities/log/log';
|
|
3
4
|
import type { ServerComponentRequest } from './framework/Hydration/ServerComponentRequest.server';
|
|
5
|
+
import type { ServerComponentResponse } from './framework/Hydration/ServerComponentResponse.server';
|
|
4
6
|
import type { Metafield, Image, MediaContentType } from './graphql/types/types';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
declare type CommonOptions = {
|
|
8
|
+
App: any;
|
|
9
|
+
pages?: ImportGlobEagerOutput;
|
|
8
10
|
request: ServerComponentRequest;
|
|
11
|
+
componentResponse: ServerComponentResponse;
|
|
12
|
+
log: Logger;
|
|
13
|
+
dev?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare type RendererOptions = CommonOptions & {
|
|
9
16
|
template: string;
|
|
10
17
|
nonce?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare type Streamer = (url: URL, options: {
|
|
14
|
-
request: ServerComponentRequest;
|
|
18
|
+
};
|
|
19
|
+
export declare type StreamerOptions = CommonOptions & {
|
|
15
20
|
response?: ServerResponse;
|
|
16
21
|
template: string;
|
|
17
22
|
nonce?: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare type Hydrator = (url: URL, options: {
|
|
21
|
-
request: ServerComponentRequest;
|
|
23
|
+
};
|
|
24
|
+
export declare type HydratorOptions = CommonOptions & {
|
|
22
25
|
response?: ServerResponse;
|
|
23
26
|
isStreamable: boolean;
|
|
24
|
-
dev?: boolean;
|
|
25
|
-
}) => void;
|
|
26
|
-
export declare type EntryServerHandler = {
|
|
27
|
-
render: Renderer;
|
|
28
|
-
stream: Streamer;
|
|
29
|
-
hydrate: Hydrator;
|
|
30
|
-
getApiRoute: (url: URL) => ApiRouteMatch | null;
|
|
31
|
-
log: Logger;
|
|
32
27
|
};
|
|
33
28
|
export declare type ShopifyConfig = {
|
|
34
29
|
defaultLocale?: string;
|
|
@@ -47,7 +42,6 @@ export declare type ServerHandlerConfig = {
|
|
|
47
42
|
export declare type ClientHandlerConfig = {
|
|
48
43
|
shopifyConfig: ShopifyConfig;
|
|
49
44
|
};
|
|
50
|
-
export declare type ServerHandler = (App: any, config: ServerHandlerConfig) => EntryServerHandler;
|
|
51
45
|
export declare type ClientHandler = (App: any, config: ClientHandlerConfig) => Promise<void>;
|
|
52
46
|
export interface GraphQLConnection<T> {
|
|
53
47
|
edges?: {
|
|
@@ -58,7 +52,7 @@ export interface MediaImage {
|
|
|
58
52
|
__typename?: string;
|
|
59
53
|
id?: string;
|
|
60
54
|
mediaContentType?: MediaContentType;
|
|
61
|
-
|
|
55
|
+
data?: Pick<Image, 'altText' | 'url' | 'id' | 'width' | 'height'>;
|
|
62
56
|
}
|
|
63
57
|
interface ProductVariant {
|
|
64
58
|
__typename?: string;
|
|
@@ -83,14 +77,20 @@ export interface Measurement {
|
|
|
83
77
|
value: number;
|
|
84
78
|
}
|
|
85
79
|
export declare type QueryKey = string | readonly unknown[];
|
|
86
|
-
export
|
|
87
|
-
|
|
80
|
+
export declare type NoStoreStrategy = {
|
|
81
|
+
mode: string;
|
|
82
|
+
};
|
|
83
|
+
export interface AllCacheOptions {
|
|
84
|
+
mode?: string;
|
|
88
85
|
maxAge?: number;
|
|
89
86
|
staleWhileRevalidate?: number;
|
|
90
|
-
|
|
87
|
+
sMaxAge?: number;
|
|
88
|
+
staleIfError?: number;
|
|
91
89
|
}
|
|
90
|
+
export declare type CachingStrategy = NoStoreStrategy | AllCacheOptions;
|
|
92
91
|
export interface HydrogenVitePluginOptions {
|
|
93
92
|
devCache?: boolean;
|
|
94
93
|
purgeQueryCacheOnBuild?: boolean;
|
|
95
94
|
}
|
|
95
|
+
export declare type PreloadOptions = boolean | string;
|
|
96
96
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ImportGlobEagerOutput } from '../types';
|
|
2
|
-
import { Logger } from '../utilities/log/log';
|
|
3
2
|
declare type RouteParams = Record<string, string>;
|
|
4
3
|
declare type RequestOptions = {
|
|
5
4
|
params: RouteParams;
|
|
@@ -17,5 +16,5 @@ export declare type ApiRouteMatch = {
|
|
|
17
16
|
};
|
|
18
17
|
export declare function getApiRoutesFromPages(pages: ImportGlobEagerOutput | undefined, topLevelPath?: string): Array<HydrogenApiRoute>;
|
|
19
18
|
export declare function getApiRouteFromURL(url: URL, routes: Array<HydrogenApiRoute>): ApiRouteMatch | null;
|
|
20
|
-
export declare function renderApiRoute(request: Request, route: ApiRouteMatch
|
|
19
|
+
export declare function renderApiRoute(request: Request, route: ApiRouteMatch): Promise<Response>;
|
|
21
20
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { matchPath } from './matchPath';
|
|
2
|
-
import { logServerResponse } from '../utilities/log/
|
|
2
|
+
import { getLoggerWithContext, logServerResponse } from '../utilities/log/';
|
|
3
3
|
let memoizedRoutes = [];
|
|
4
4
|
let memoizedPages = {};
|
|
5
5
|
export function getApiRoutesFromPages(pages, topLevelPath = '*') {
|
|
@@ -61,8 +61,9 @@ export function getApiRouteFromURL(url, routes) {
|
|
|
61
61
|
hasServerComponent: foundRoute.hasServerComponent,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
export async function renderApiRoute(request, route
|
|
64
|
+
export async function renderApiRoute(request, route) {
|
|
65
65
|
let response;
|
|
66
|
+
const log = getLoggerWithContext(request);
|
|
66
67
|
try {
|
|
67
68
|
response = await route.resource(request, { params: route.params });
|
|
68
69
|
if (!(response instanceof Response)) {
|
|
@@ -82,6 +83,6 @@ export async function renderApiRoute(request, route, log) {
|
|
|
82
83
|
log.error(e);
|
|
83
84
|
response = new Response('Error processing: ' + request.url, { status: 500 });
|
|
84
85
|
}
|
|
85
|
-
logServerResponse('api',
|
|
86
|
+
logServerResponse('api', request, response.status);
|
|
86
87
|
return response;
|
|
87
88
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An alphabetized list of User Agents of known bots, combined from lists found at:
|
|
3
|
+
* https://github.com/vercel/next.js/blob/d87dc2b5a0b3fdbc0f6806a47be72bad59564bd0/packages/next/server/utils.ts#L18-L22
|
|
4
|
+
* https://github.com/GoogleChrome/rendertron/blob/6f681688737846b28754fbfdf5db173846a826df/middleware/src/middleware.ts#L24-L41
|
|
5
|
+
*/
|
|
6
|
+
const botUserAgents = [
|
|
7
|
+
'AdsBot-Google',
|
|
8
|
+
'applebot',
|
|
9
|
+
'Baiduspider',
|
|
10
|
+
'baiduspider',
|
|
11
|
+
'bingbot',
|
|
12
|
+
'Bingbot',
|
|
13
|
+
'BingPreview',
|
|
14
|
+
'bitlybot',
|
|
15
|
+
'Discordbot',
|
|
16
|
+
'DuckDuckBot',
|
|
17
|
+
'Embedly',
|
|
18
|
+
'facebookcatalog',
|
|
19
|
+
'facebookexternalhit',
|
|
20
|
+
'Google-PageRenderer',
|
|
21
|
+
'Googlebot',
|
|
22
|
+
'googleweblight',
|
|
23
|
+
'ia_archive',
|
|
24
|
+
'LinkedInBot',
|
|
25
|
+
'Mediapartners-Google',
|
|
26
|
+
'outbrain',
|
|
27
|
+
'pinterest',
|
|
28
|
+
'quora link preview',
|
|
29
|
+
'redditbot',
|
|
30
|
+
'rogerbot',
|
|
31
|
+
'showyoubot',
|
|
32
|
+
'SkypeUriPreview',
|
|
33
|
+
'Slackbot',
|
|
34
|
+
'Slurp',
|
|
35
|
+
'sogou',
|
|
36
|
+
'Storebot-Google',
|
|
37
|
+
'TelegramBot',
|
|
38
|
+
'tumblr',
|
|
39
|
+
'Twitterbot',
|
|
40
|
+
'vkShare',
|
|
41
|
+
'W3C_Validator',
|
|
42
|
+
'WhatsApp',
|
|
43
|
+
'yandex',
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Creates a regex based on the botUserAgents array
|
|
47
|
+
*/
|
|
48
|
+
const botUARegex = new RegExp(botUserAgents.join('|'), 'i');
|
|
49
|
+
/**
|
|
50
|
+
* Determines if the request is from a bot, using the URL and User Agent
|
|
51
|
+
*/
|
|
52
|
+
export function isBotUA(url, userAgent) {
|
|
53
|
+
return (url.searchParams.has('_bot') || (!!userAgent && botUARegex.test(userAgent)));
|
|
54
|
+
}
|
|
@@ -10,33 +10,8 @@ export function fetchBuilder(request) {
|
|
|
10
10
|
request.headers.append(property, value);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
let body;
|
|
14
13
|
return async () => {
|
|
15
|
-
|
|
16
|
-
// and throws at the attempt afterwards,
|
|
17
|
-
// and this function can be cached and re-used, we cache
|
|
18
|
-
// the body in the outer scope.
|
|
19
|
-
if (!body) {
|
|
20
|
-
body = await request.text();
|
|
21
|
-
}
|
|
22
|
-
// Oxygen's fetch is a Go implementation which
|
|
23
|
-
// currently doesn't process some the call
|
|
24
|
-
// signatures well. Specifically, it can't
|
|
25
|
-
// consume request/response "body" property
|
|
26
|
-
// if it follows the standard and is a ReadableStream
|
|
27
|
-
// instance. It worked before because old Fetch API polyfills
|
|
28
|
-
// in Oxygen didn't follow the standard but soon they will,
|
|
29
|
-
// and we have to adjust the way we call fetch().
|
|
30
|
-
// Oxygen aims at being eventually compliant
|
|
31
|
-
// with the Fetch API, making these quirks redundant.
|
|
32
|
-
// Headers must be a plain object unless the whole second argument is instanceof Request
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
const headers = Object.fromEntries(request.headers.entries());
|
|
35
|
-
const response = await fetch(request.url, {
|
|
36
|
-
body,
|
|
37
|
-
headers,
|
|
38
|
-
method: request.method,
|
|
39
|
-
});
|
|
14
|
+
const response = await fetch(request.url, request);
|
|
40
15
|
if (!response.ok) {
|
|
41
16
|
throw response;
|
|
42
17
|
}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export { log, setLogger, Logger, logServerResponse,
|
|
1
|
+
export { log, setLogger, setLoggerOptions, getLoggerWithContext, Logger, logServerResponse, resetLogger, } from './log';
|
|
2
|
+
export { collectQueryCacheControlHeaders, logCacheControlHeaders, } from './log-cache-header';
|
|
3
|
+
export { logCacheApiStatus } from './log-cache-api-status';
|
|
4
|
+
export { collectQueryTimings, logQueryTimings } from './log-query-timeline';
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export { log, setLogger,
|
|
1
|
+
export { log, setLogger, setLoggerOptions, getLoggerWithContext, logServerResponse, resetLogger, } from './log';
|
|
2
|
+
export { collectQueryCacheControlHeaders, logCacheControlHeaders, } from './log-cache-header';
|
|
3
|
+
export { logCacheApiStatus } from './log-cache-api-status';
|
|
4
|
+
export { collectQueryTimings, logQueryTimings } from './log-query-timeline';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logCacheApiStatus(status: string | null, url: string): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { findQueryName } from './utils';
|
|
2
|
+
import { gray } from 'kolorist';
|
|
3
|
+
import { log } from '.';
|
|
4
|
+
export function logCacheApiStatus(status, url) {
|
|
5
|
+
if (!log.options().showCacheApiStatus) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
log.debug(gray(`[Cache] ${status === null || status === void 0 ? void 0 : status.padEnd(6)} query ${findQueryName(url)}`));
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ServerComponentRequest } from '../../framework/Hydration/ServerComponentRequest.server';
|
|
2
|
+
import { ServerComponentResponse } from '../../framework/Hydration/ServerComponentResponse.server';
|
|
3
|
+
import { QueryKey } from '../../types';
|
|
4
|
+
import type { RenderType } from './log';
|
|
5
|
+
export declare type QueryCacheControlHeaders = {
|
|
6
|
+
name: string;
|
|
7
|
+
header: string | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function collectQueryCacheControlHeaders(request: ServerComponentRequest, queryKey: QueryKey, cacheControlHeader: string | null): void;
|
|
10
|
+
export declare function logCacheControlHeaders(type: RenderType, request: ServerComponentRequest, response?: ServerComponentResponse): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { hashKey } from '../../framework/cache';
|
|
2
|
+
import { findQueryName, parseUrl } from './utils';
|
|
3
|
+
import { gray } from 'kolorist';
|
|
4
|
+
import { getLoggerWithContext } from './log';
|
|
5
|
+
const color = gray;
|
|
6
|
+
export function collectQueryCacheControlHeaders(request, queryKey, cacheControlHeader) {
|
|
7
|
+
request.ctx.queryCacheControl.push({
|
|
8
|
+
name: findQueryName(hashKey(queryKey)),
|
|
9
|
+
header: cacheControlHeader,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function logCacheControlHeaders(type, request, response) {
|
|
13
|
+
const log = getLoggerWithContext(request);
|
|
14
|
+
if (!log.options().showCacheControlHeader) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
log.debug(color(`┌── Cache control header for ${parseUrl(type, request.url)}`));
|
|
18
|
+
if (response) {
|
|
19
|
+
log.debug(color(`│ ${response.cacheControlHeader}`));
|
|
20
|
+
}
|
|
21
|
+
const queryList = request.ctx.queryCacheControl;
|
|
22
|
+
const longestQueryNameLength = queryList.reduce((max, query) => Math.max(max, query.name.length), 0);
|
|
23
|
+
if (queryList.length > 0) {
|
|
24
|
+
log.debug(color('│'));
|
|
25
|
+
queryList.forEach((query) => {
|
|
26
|
+
log.debug(color(`│ query ${query.name.padEnd(longestQueryNameLength + 1)}${query.header}`));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
log.debug(color('└──'));
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ServerComponentRequest } from '../../framework/Hydration/ServerComponentRequest.server';
|
|
2
|
+
import { QueryKey } from '../../types';
|
|
3
|
+
import type { RenderType } from './log';
|
|
4
|
+
export declare type TimingType = 'requested' | 'resolved' | 'rendered' | 'preload';
|
|
5
|
+
export declare type QueryTiming = {
|
|
6
|
+
name: string;
|
|
7
|
+
timingType: TimingType;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
duration?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function collectQueryTimings(request: ServerComponentRequest, queryKey: QueryKey, timingType: TimingType, duration?: number): void;
|
|
12
|
+
export declare function logQueryTimings(type: RenderType, request: ServerComponentRequest): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { hashKey } from '../../framework/cache';
|
|
2
|
+
import { findQueryName, parseUrl } from './utils';
|
|
3
|
+
import { gray, red, yellow, green } from 'kolorist';
|
|
4
|
+
import { getLoggerWithContext } from './log';
|
|
5
|
+
import { getTime } from '../timing';
|
|
6
|
+
const color = gray;
|
|
7
|
+
const TIMING_MAPPING = {
|
|
8
|
+
requested: 'Requested',
|
|
9
|
+
rendered: 'Rendered',
|
|
10
|
+
resolved: 'Resolved',
|
|
11
|
+
preload: 'Preload',
|
|
12
|
+
};
|
|
13
|
+
export function collectQueryTimings(request, queryKey, timingType, duration) {
|
|
14
|
+
request.ctx.queryTimings.push({
|
|
15
|
+
name: findQueryName(hashKey(queryKey)),
|
|
16
|
+
timingType,
|
|
17
|
+
timestamp: getTime(),
|
|
18
|
+
duration,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function logQueryTimings(type, request) {
|
|
22
|
+
const log = getLoggerWithContext(request);
|
|
23
|
+
if (!log.options().showQueryTiming) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
log.debug(color(`┌── Query timings for ${parseUrl(type, request.url)}`));
|
|
27
|
+
const queryList = request.ctx.queryTimings;
|
|
28
|
+
if (queryList.length > 0) {
|
|
29
|
+
const requestStartTime = request.time;
|
|
30
|
+
const detectSuspenseWaterfall = {};
|
|
31
|
+
const detectMultipleDataLoad = {};
|
|
32
|
+
let suspenseWaterfallDetectedCount = 0;
|
|
33
|
+
queryList.forEach((query, index) => {
|
|
34
|
+
var _a;
|
|
35
|
+
if (query.timingType === 'requested' || query.timingType === 'preload') {
|
|
36
|
+
detectSuspenseWaterfall[query.name] = true;
|
|
37
|
+
}
|
|
38
|
+
else if (query.timingType === 'rendered') {
|
|
39
|
+
delete detectSuspenseWaterfall[query.name];
|
|
40
|
+
}
|
|
41
|
+
else if (query.timingType === 'resolved') {
|
|
42
|
+
detectMultipleDataLoad[query.name] = detectMultipleDataLoad[query.name]
|
|
43
|
+
? detectMultipleDataLoad[query.name] + 1
|
|
44
|
+
: 1;
|
|
45
|
+
}
|
|
46
|
+
const loadColor = query.timingType === 'preload' ? green : color;
|
|
47
|
+
log.debug(color(`│ ${`${(query.timestamp - requestStartTime).toFixed(2)}ms`.padEnd(10)} ${loadColor(TIMING_MAPPING[query.timingType].padEnd(10))} ${query.name}${query.timingType === 'resolved'
|
|
48
|
+
? ` (Took ${(_a = query.duration) === null || _a === void 0 ? void 0 : _a.toFixed(2)}ms)`
|
|
49
|
+
: ''}`));
|
|
50
|
+
// SSR + RSC render path generates 2 `load` and `render` for each query
|
|
51
|
+
// We want to avoid falsely identifying a suspense waterfall near the end
|
|
52
|
+
// of the query list
|
|
53
|
+
//
|
|
54
|
+
// The (index + 4) is detecting that near the end of list.
|
|
55
|
+
// A complete set of events for a given query is 4 entries
|
|
56
|
+
// │ (639.62ms) Requested Localization
|
|
57
|
+
// │ (993.33ms) Resolved Localization (Took 353.66ms)
|
|
58
|
+
// │ (993.96ms) Requested Localization <-- second time React tries to load
|
|
59
|
+
// │ (994.03ms) Rendered Localization
|
|
60
|
+
//
|
|
61
|
+
// so the end of list index range is 3 (one less from a set entry) + 1 (zero index)
|
|
62
|
+
if (queryList.length >= index + 4 &&
|
|
63
|
+
Object.keys(detectSuspenseWaterfall).length === 0) {
|
|
64
|
+
suspenseWaterfallDetectedCount++;
|
|
65
|
+
const warningColor = suspenseWaterfallDetectedCount === 1 ? yellow : red;
|
|
66
|
+
log.debug(`${color(`│ `)}${warningColor(`Suspense waterfall detected`)}`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const unusedQueries = Object.keys(detectSuspenseWaterfall);
|
|
70
|
+
if (unusedQueries.length > 0) {
|
|
71
|
+
unusedQueries.forEach((queryName) => {
|
|
72
|
+
log.debug(`${color(`│ `)}${yellow(`Unused query detected: ${queryName}`)}`);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
Object.keys(detectMultipleDataLoad).forEach((queryName) => {
|
|
76
|
+
const count = detectMultipleDataLoad[queryName];
|
|
77
|
+
if (count > 1) {
|
|
78
|
+
log.debug(`${color(`│ `)}${yellow(`Multiple data loads detected: ${queryName}`)}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
log.debug(color('└──'));
|
|
83
|
+
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { ServerComponentRequest } from '../../framework/Hydration/ServerComponentRequest.server';
|
|
2
|
-
/** The `log` utility is a function that's used for logging debugging, warning, and error information about the application.
|
|
3
|
-
* Use this utility by importing `log` from `@shopify/hydrogen`, or by using a `log` prop passed to each page
|
|
4
|
-
* component. We recommend using the `log` prop passed to each page because it will associated your log to the
|
|
5
|
-
* current request in progress.
|
|
6
|
-
*/
|
|
7
2
|
export interface Logger {
|
|
8
3
|
trace: (...args: Array<any>) => void;
|
|
9
4
|
debug: (...args: Array<any>) => void;
|
|
10
5
|
warn: (...args: Array<any>) => void;
|
|
11
6
|
error: (...args: Array<any>) => void;
|
|
12
7
|
fatal: (...args: Array<any>) => void;
|
|
8
|
+
options: () => LoggerOptions;
|
|
13
9
|
}
|
|
14
|
-
export declare
|
|
10
|
+
export declare type LoggerOptions = {
|
|
11
|
+
showCacheControlHeader?: boolean;
|
|
12
|
+
showCacheApiStatus?: boolean;
|
|
13
|
+
showQueryTiming?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare type RenderType = 'str' | 'rsc' | 'ssr' | 'api';
|
|
16
|
+
export declare const log: Logger;
|
|
17
|
+
export declare function getLoggerWithContext(context?: any): Logger;
|
|
15
18
|
export declare function setLogger(newLogger: Logger): void;
|
|
19
|
+
export declare function setLoggerOptions(options: LoggerOptions): void;
|
|
16
20
|
export declare function resetLogger(): void;
|
|
17
|
-
export declare
|
|
18
|
-
export declare function logServerResponse(type: 'str' | 'rsc' | 'ssr' | 'api', log: Logger, request: ServerComponentRequest, responseStatus: number): void;
|
|
21
|
+
export declare function logServerResponse(type: RenderType, request: ServerComponentRequest, responseStatus: number): void;
|