-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nextjs] Update feaas clientside and adjust types in byoc bundlers
- Loading branch information
1 parent
e817e8c
commit 0de9aae
Showing
6 changed files
with
48 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 17 additions & 10 deletions
27
packages/create-sitecore-jss/src/templates/nextjs/src/byoc/index.client.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import * as FEAAS from '@sitecore-feaas/clientside/react'; | ||
import React from 'react'; | ||
import { ComponentProps } from 'react'; | ||
/** | ||
* Below are built-in JSS imports. These should be available in Pages, if a license required for specific components is present | ||
* Any built-in import can be removed if not used. | ||
* Below are Sitecore default BYOC components. Included components will be available in Pages and Components apps out of the | ||
* box for convenience. It is advised to comment out unused components when application is ready for production | ||
* to reduce javascript bundle size. | ||
*/ | ||
|
||
// SitecoreForm component which enables Forms for XM Cloud functionality. Requires a license to be available in Pages. | ||
// SitecoreForm component displays forms created in XM Forms as individual components to be embedded into Pages. | ||
// Sitecore Forms for Sitecore XP are still available separately via @sitecore-jss-forms package | ||
import '@sitecore/components/form'; | ||
|
||
/** | ||
* End of built-in JSS imports | ||
* You can import your own client component below, for example | ||
* You can import your own client component below | ||
* @example | ||
* import './MyClientComponent'; | ||
* @example | ||
* import 'src/otherFolder/MyOtherComponent'; | ||
*/ | ||
|
||
// An important boilerplate component that prevents BYOC components from being optimized away. Should be kept in this file. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const DefaultExport = (props: ComponentProps<any>) => FEAAS.ExternalComponent(props) || <></>; | ||
export default DefaultExport; | ||
// An important boilerplate component that prevents BYOC components from being optimized away and allows then. Should be kept in this file. | ||
const ClientsideComponent = (props: FEAAS.ExternalComponentProps) => FEAAS.ExternalComponent(props); | ||
/** | ||
* Clientside BYOC component will be rendered in the browser, so that external components: | ||
* - Can have access to DOM apis, including network requests | ||
* - Use clientside react hooks like useEffect. | ||
* - Be implemented as web components. | ||
*/ | ||
export default ClientsideComponent; |
9 changes: 5 additions & 4 deletions
9
packages/create-sitecore-jss/src/templates/nextjs/src/byoc/index.hybrid.ts
This file contains 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
15 changes: 9 additions & 6 deletions
15
packages/create-sitecore-jss/src/templates/nextjs/src/byoc/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
// This is an out-of-box bundler for External components (BYOC) | ||
// It enables registering components in client-only or SSR/hybrid contexts | ||
// It's recommended to not modify this file - please add BYOC imports in corresponding index.*.ts files instead | ||
import * as FEAAS from '@sitecore-feaas/clientside/react'; | ||
/** | ||
* This is an out-of-box bundler for External components (BYOC) (see Sitecore documentation for more details) | ||
* It enables registering components in client-only or SSR/hybrid contexts | ||
* It's recommended to not modify this file - please add BYOC imports in corresponding index.*.ts files instead | ||
*/ | ||
|
||
// Import your client-only components via client-bundle. Nextjs's dynamic() call will ensure they are only rendered client-side | ||
import dynamic from 'next/dynamic'; | ||
const ClientBundle = dynamic(() => import('./index.client'), { | ||
ssr: false, | ||
}); | ||
FEAAS.enableNextClientsideComponents(dynamic, ClientBundle); | ||
|
||
// Import your SSR/hybrid components via index.hybrid.ts | ||
// Import your hybrid (server rendering with client hydration) components via index.hybrid.ts | ||
import './index.hybrid'; | ||
|
||
// As long as client bundle is exported and rendered on page (as an empty element), client-only BYOC components are registered and become available | ||
// The rest of components will be regsitered in both server and client-side contexts when this module is imported into Layout | ||
export default ClientBundle; | ||
|
||
export default FEAAS.ExternalComponentBundle; |
This file contains 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
This file contains 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