Skip to content

Commit 8fd137a

Browse files
committed
Resolved build failures-IV
1 parent 07665ee commit 8fd137a

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

headapps/Sugcon2024/.storybook/main.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type { StorybookConfig } from '@storybook/nextjs';
22
import path from 'path';
33

44
const config: StorybookConfig = {
5-
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5+
// If you DO have MDX stories, keep the MDX line; otherwise comment it out.
6+
stories: [
7+
// '../src/**/*.mdx',
8+
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
9+
],
610
addons: [
711
'@storybook/addon-links',
812
'@storybook/addon-essentials',
@@ -16,18 +20,25 @@ const config: StorybookConfig = {
1620
docs: {
1721
autodocs: 'tag',
1822
},
19-
staticDirs: ['../public', '../public/images'],
20-
webpackFinal: async (config) => {
21-
// Ensure the existence of config.resolve and config.resolve.alias
22-
config.resolve = config.resolve || {};
23-
config.resolve.alias = config.resolve.alias || {};
23+
// `public/images` is already inside `public`, so one entry is enough
24+
staticDirs: ['../public'],
25+
26+
webpackFinal: async (cfg) => {
27+
// Storybook's webpack config defaults to production mode, which causes
28+
// minification and dead code elimination. This interferes with some of
29+
// our conditional code that relies on process.env.NODE_ENV checks.
30+
(cfg as any).cache = false; // cache: false
2431

25-
Object.assign(config.resolve.alias, {
32+
33+
cfg.resolve = cfg.resolve || {};
34+
cfg.resolve.alias = cfg.resolve.alias || {};
35+
Object.assign(cfg.resolve.alias, {
2636
'@sass': path.resolve(__dirname, '../src/assets/sass'),
2737
'@fontawesome': path.join(__dirname, '../node_modules', 'font-awesome'),
2838
});
2939

30-
return config;
40+
return cfg;
3141
},
3242
};
43+
3344
export default config;

headapps/Sugcon2024/src/components/CdpPageView.tsx

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
SiteInfo,
55
useSitecoreContext,
66
} from '@sitecore-jss/sitecore-jss-nextjs';
7-
import { useEffect } from 'react';
7+
import { useCallback, useEffect } from 'react';
88
import config from 'temp/config';
99
import { init } from '@sitecore/engage';
1010
import { siteResolver } from 'lib/site-resolver';
@@ -27,30 +27,26 @@ const CdpPageView = (): JSX.Element => {
2727
/**
2828
* Creates a page view event using the Sitecore Engage SDK.
2929
*/
30-
const createPageView = async (
31-
page: string,
32-
language: string,
33-
site: SiteInfo,
34-
pageVariantId: string
35-
) => {
36-
const pointOfSale = resolvePointOfSale(site, language);
37-
const engage = await init({
38-
clientKey: process.env.NEXT_PUBLIC_CDP_CLIENT_KEY || '',
39-
targetURL: process.env.NEXT_PUBLIC_CDP_TARGET_URL || '',
40-
// Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com"
41-
cookieDomain: window.location.hostname.replace(/^www\./, ''),
42-
// Cookie may be created in personalize middleware (server), but if not we should create it here
43-
forceServerCookieMode: false,
44-
});
45-
engage.pageView({
46-
channel: 'WEB',
47-
currency: 'USD',
48-
pointOfSale,
49-
page,
50-
pageVariantId,
51-
language,
52-
});
53-
};
30+
const createPageView = useCallback(
31+
async (page: string, language: string, site: SiteInfo, pageVariantId: string) => {
32+
const pointOfSale = resolvePointOfSale(site, language);
33+
const engage = await init({
34+
clientKey: process.env.NEXT_PUBLIC_CDP_CLIENT_KEY || '',
35+
targetURL: process.env.NEXT_PUBLIC_CDP_TARGET_URL || '',
36+
cookieDomain: window.location.hostname.replace(/^www\./, ''),
37+
forceServerCookieMode: false,
38+
});
39+
engage.pageView({
40+
channel: 'WEB',
41+
currency: 'USD',
42+
pointOfSale,
43+
page,
44+
pageVariantId,
45+
language,
46+
});
47+
},
48+
[] // Empty dependency array, so it will only be created once.
49+
);
5450

5551
/**
5652
* Determines if the page view events should be turned off.
@@ -87,7 +83,7 @@ const CdpPageView = (): JSX.Element => {
8783
scope
8884
);
8985
createPageView(route.name, language, siteInfo, pageVariantId);
90-
}, [pageState, route, variantId, site]);
86+
}, [pageState, route, variantId, site, createPageView]);
9187

9288
return <></>;
9389
};

headapps/Sugcon2024/src/pages/[[...path]].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { GetStaticPaths, GetStaticProps } from 'next';
33
import NotFound from 'src/NotFound';
44
import Layout from 'src/Layout';
55
import {
6-
RenderingType,
76
SitecoreContext,
87
ComponentPropsContext,
98
StaticPath,

headapps/Sugcon2024/src/stories/components/Basic Components/Navigation.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Meta, StoryObj } from '@storybook/react';
22
import { Default as Navigation } from 'components/Navigation';
3-
import { SitecoreContext } from '@sitecore-jss/sitecore-jss-react';
3+
import { SitecoreContext } from '@sitecore-jss/sitecore-jss-nextjs';
44

55
const meta = {
66
title: 'Basic Components/Navigation',

0 commit comments

Comments
 (0)