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] Handle BYOC Component error #1621

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Our versioning strategy is as follows:
* `[templates/nextjs]` `[sitecore-jss-nextjs]` Better error handling for component-level data fetching ([#1586](https://github.com/Sitecore/jss/pull/1586))
* `[sitecore-jss-react]` Fetch Data for FEaaS Components as part of Component SSR/SSG ([#1586](https://github.com/Sitecore/jss/pull/1590))
* `[sitecore-jss-dev-tools]` `[templates/nextjs]` `[templates/react]` Introduce "components" configuration for ComponentBuilder ([#1598](https://github.com/Sitecore/jss/pull/1598))
* `[sitecore-jss-react]` `[sitecore-jss-nextjs]` Component level data fetching(SSR/SSG) for BYOC ([#1610](https://github.com/Sitecore/jss/pull/1610))
* `[sitecore-jss-react]` `[sitecore-jss-nextjs]` Component level data fetching(SSR/SSG) for BYOC ([#1610](https://github.com/Sitecore/jss/pull/1610)) ([#1621](https://github.com/Sitecore/jss/pull/1621))
* `[sitecore-jss-nextjs]` Reduce the amount of Edge API calls during fetch getStaticPaths ([#1612](https://github.com/Sitecore/jss/pull/1612))
* `[sitecore-jss]` `[templates/nextjs]` GraphQL Layout and Dictionary services can handle endpoint rate limits through retryer functionality in GraphQLClient. To prevent SSG builds from failing and enable multiple retries, set retry amount in lib/dictionary-service-factory and lib/layout-service-factory ([#1618](https://github.com/Sitecore/jss/pull/1618))
* `[templates/nextjs]` `[sitecore-jss-nextjs]` Upgrade Nextjs to 13.4.16([#1616](https://github.com/Sitecore/jss/pull/1616))
Expand Down
24 changes: 24 additions & 0 deletions packages/sitecore-jss-react/src/components/BYOCComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ describe('BYOCComponent', () => {
expect(fooComponent.prop('data-external-id')).to.equal('Foo');
expect(fooComponent.find('#foo-content')).to.have.length(1);
});

it('should render with props when ComponentProps are provided but fetchedData is not present', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
},
};
const Foo = () => <p id="foo-content">Test</p>;
FEAAS.External.registerComponent(Foo, {
name: 'Foo',
properties: {
prop1: {
type: 'string',
},
},
});
const wrapper = mount(<BYOCComponent {...mockProps} />);
const fooComponent = wrapper.find('feaas-external');
expect(fooComponent).to.have.lengthOf(1);
expect(fooComponent.prop('prop1')).to.equal('value1');
expect(fooComponent.prop('data-external-id')).to.equal('Foo');
expect(fooComponent.find('#foo-content')).to.have.length(1);
});
});

describe('Error handling', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class BYOCComponent extends React.Component<BYOCComponentProps> {

const ErrorComponent = this.props.errorComponent;

const isNull = Object.keys(props.fetchedData).length === 0;
const isNull = props.fetchedData && Object.keys(props.fetchedData).length === 0;

let componentProps: { [key: string]: any } = isNull ? null : props.fetchedData;

Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6457,7 +6457,7 @@ __metadata:
"@angular/platform-browser": ~15.2.9
"@angular/platform-browser-dynamic": ~15.2.9
"@angular/router": ~15.2.9
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/jasmine": ^3.4.1
"@types/node": ^14.14.35
codelyzer: ^6.0.1
Expand Down Expand Up @@ -6488,7 +6488,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-cli@workspace:packages/sitecore-jss-cli"
dependencies:
"@sitecore-jss/sitecore-jss-dev-tools": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss-dev-tools": 21.5.0-canary.2
"@types/chai": ^4.2.4
"@types/cross-spawn": ^6.0.2
"@types/mocha": ^10.0.1
Expand Down Expand Up @@ -6520,11 +6520,11 @@ __metadata:
languageName: unknown
linkType: soft

"@sitecore-jss/sitecore-jss-dev-tools@^21.5.0-canary.2, @sitecore-jss/sitecore-jss-dev-tools@workspace:packages/sitecore-jss-dev-tools":
"@sitecore-jss/sitecore-jss-dev-tools@21.5.0-canary.2, @sitecore-jss/sitecore-jss-dev-tools@workspace:packages/sitecore-jss-dev-tools":
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-dev-tools@workspace:packages/sitecore-jss-dev-tools"
dependencies:
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/chai": ^4.3.4
"@types/chokidar": ^2.1.3
"@types/del": ^4.0.0
Expand Down Expand Up @@ -6576,11 +6576,11 @@ __metadata:
languageName: unknown
linkType: soft

"@sitecore-jss/sitecore-jss-forms@^21.5.0-canary.2, @sitecore-jss/sitecore-jss-forms@workspace:packages/sitecore-jss-forms":
"@sitecore-jss/sitecore-jss-forms@21.5.0-canary.2, @sitecore-jss/sitecore-jss-forms@workspace:packages/sitecore-jss-forms":
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-forms@workspace:packages/sitecore-jss-forms"
dependencies:
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/chai": ^4.3.4
"@types/chai-string": ^1.4.2
"@types/lodash.unescape": ^4.0.7
Expand All @@ -6603,9 +6603,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-nextjs@workspace:packages/sitecore-jss-nextjs"
dependencies:
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss-dev-tools": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss-react": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@sitecore-jss/sitecore-jss-dev-tools": 21.5.0-canary.2
"@sitecore-jss/sitecore-jss-react": 21.5.0-canary.2
"@types/chai": ^4.3.4
"@types/chai-as-promised": ^7.1.5
"@types/chai-string": ^1.4.2
Expand Down Expand Up @@ -6677,7 +6677,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-react-forms@workspace:packages/sitecore-jss-react-forms"
dependencies:
"@sitecore-jss/sitecore-jss-forms": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss-forms": 21.5.0-canary.2
"@types/chai": ^4.3.4
"@types/enzyme": ^3.10.12
"@types/mocha": ^10.0.1
Expand Down Expand Up @@ -6717,7 +6717,7 @@ __metadata:
"@babel/plugin-proposal-export-default-from": ^7.5.2
"@babel/preset-env": ^7.6.2
"@babel/preset-typescript": ^7.6.0
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/jest": ^24.0.18
"@types/prop-types": ^15.7.3
"@types/react": ^16.9.5
Expand Down Expand Up @@ -6747,12 +6747,12 @@ __metadata:
languageName: unknown
linkType: soft

"@sitecore-jss/sitecore-jss-react@^21.5.0-canary.2, @sitecore-jss/sitecore-jss-react@workspace:packages/sitecore-jss-react":
"@sitecore-jss/sitecore-jss-react@21.5.0-canary.2, @sitecore-jss/sitecore-jss-react@workspace:packages/sitecore-jss-react":
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss-react@workspace:packages/sitecore-jss-react"
dependencies:
"@sitecore-feaas/clientside": ^0.3.17
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/chai": ^4.3.4
"@types/chai-string": ^1.4.2
"@types/deep-equal": ^1.0.1
Expand Down Expand Up @@ -6826,7 +6826,7 @@ __metadata:
resolution: "@sitecore-jss/sitecore-jss-vue@workspace:packages/sitecore-jss-vue"
dependencies:
"@babel/core": ^7.20.12
"@sitecore-jss/sitecore-jss": ^21.5.0-canary.2
"@sitecore-jss/sitecore-jss": 21.5.0-canary.2
"@types/jest": ^29.2.6
"@types/node": ^18.11.18
"@vue/compiler-dom": ^3.2.45
Expand All @@ -6850,7 +6850,7 @@ __metadata:
languageName: unknown
linkType: soft

"@sitecore-jss/sitecore-jss@^21.5.0-canary.2, @sitecore-jss/sitecore-jss@workspace:packages/sitecore-jss":
"@sitecore-jss/sitecore-jss@21.5.0-canary.2, @sitecore-jss/sitecore-jss@workspace:packages/sitecore-jss":
version: 0.0.0-use.local
resolution: "@sitecore-jss/sitecore-jss@workspace:packages/sitecore-jss"
dependencies:
Expand Down