Skip to content
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

[sitecore-jss-react] Use ComponentDataOverride instead of ComponentProps for BYOCComponent #1682

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Our versioning strategy is as follows:

### 🐛 Bug Fixes

* [sitecore-jss-react] Use ComponentDataOverride instead of ComponentProps for BYOCComponent ([#1682](https://github.com/Sitecore/jss/pull/1682))
* `[sitecore-jss-proxy]` Setting "followRedirects" to "true" breaks HEAD requests ([#1630](https://github.com/Sitecore/jss/pull/1630))
* `[templates/nextjs-sxa]` Fix shown horizontal scrollbar in EE mode. ([#1625](https://github.com/Sitecore/jss/pull/1625)), ([#1626](https://github.com/Sitecore/jss/pull/1626))
* `[sitecore-jss-nextjs]` Fix issue when redirects works each every other times. ([#1629](https://github.com/Sitecore/jss/pull/1629))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { BYOCComponent } from './BYOCComponent';
import { MissingComponent, MissingComponentProps } from './MissingComponent';

describe('BYOCComponent', () => {
it('should render with props when ComponentProps is provided', () => {
it('should render with props when ComponentDataOverride is provided', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
fetchedData: {},
};
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('BYOCComponent', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
fetchedData,
};
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('BYOCComponent', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
};
const Foo = () => <p id="foo-content">Test</p>;
Expand All @@ -93,7 +93,7 @@ describe('Error handling', () => {
const props = {
params: {
ComponentName: 'ExampleComponent',
ComponentProps: 'invalid-json',
ComponentDataOverride: 'invalid-json',
},
fetchedData: {},
};
Expand All @@ -108,7 +108,7 @@ describe('Error handling', () => {
errorComponent: customErrorComponent,
params: {
ComponentName: 'ExampleComponent',
ComponentProps: 'invalid-json',
ComponentDataOverride: 'invalid-json',
},
fetchedData: {},
};
Expand All @@ -122,7 +122,7 @@ describe('Error handling', () => {
const props = {
params: {
ComponentName: '',
ComponentProps: JSON.stringify({ text: 'this is a BYOC component' }),
ComponentDataOverride: JSON.stringify({ text: 'this is a BYOC component' }),
},
};
const wrapper = mount(<BYOCComponent {...props} />);
Expand Down
10 changes: 5 additions & 5 deletions packages/sitecore-jss-react/src/components/BYOCComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type BYOCComponentParams = {
/**
* JSON props to pass into rendered component
*/
ComponentProps?: string;
ComponentDataOverride?: string;
/**
* A string with classes that can be used to apply themes, via SXA functionality
*/
Expand Down Expand Up @@ -133,9 +133,9 @@ export class BYOCComponent extends React.Component<BYOCComponentProps> {

let componentProps: { [key: string]: any } = null;

if (props.params?.ComponentProps) {
if (props.params?.ComponentDataOverride) {
try {
componentProps = JSON.parse(props.params.ComponentProps) ?? {};
componentProps = JSON.parse(props.params.ComponentDataOverride) ?? {};
} catch (e) {
console.error(
`Parsing props for ${componentName} component from rendering params failed. Error: ${e}`
Expand Down Expand Up @@ -169,8 +169,8 @@ export class BYOCComponent extends React.Component<BYOCComponentProps> {
export async function fetchBYOCComponentServerProps(
params: BYOCComponentParams
): Promise<BYOCComponentProps> {
const fetchDataOptions: FEAAS.DataOptions = params.ComponentProps
? JSON.parse(params.ComponentProps)
const fetchDataOptions: FEAAS.DataOptions = params.ComponentDataOverride
? JSON.parse(params.ComponentDataOverride)
: {};

const fetchedData: FEAAS.DataScopes = await FEAAS.DataSettings.fetch(fetchDataOptions || {});
Expand Down