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

PR #2039 adjustments #2046

Merged
merged 2 commits into from
Feb 25, 2025
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ Our versioning strategy is as follows:

## Unreleased

### 🎉 New Features & Improvements

* `[sitecore-jss-nextjs]` Link component supports prefetch property ([#2039](https://github.com/Sitecore/jss/pull/2039))([#2046](https://github.com/Sitecore/jss/pull/2046))

### 🐛 Bug Fixes

* `[templates/nextjs-sxa]`Fixed unsafe property access by replacing direct calls with optional chaining ([#2035](https://github.com/Sitecore/jss/pull/2035))
* `[templates/nextjs-sxa]` Fixed unsafe property access by replacing direct calls with optional chaining ([#2035](https://github.com/Sitecore/jss/pull/2035))

## 22.5.0

Expand Down
22 changes: 22 additions & 0 deletions packages/sitecore-jss-nextjs/src/components/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@ describe('<Link />', () => {
expect(c.find(ReactLink).length).to.equal(0);
});

it('should render with prefetch prop provided', () => {
const field = {
href: '/lorem',
text: 'ipsum',
};
const c = mount(
<Page>
<Link field={field} prefetch={false} />
</Page>
);

const link = c.find('a');

expect(link.html()).to.contain(field.href);
expect(link.html()).to.contain(field.text);

expect(c.find(NextLink).length).to.equal(1);
expect(c.find(ReactLink).length).to.equal(0);

expect(c.find(NextLink).props().prefetch).to.equal(false);
});

it('should render other attributes with other props provided', () => {
const field = {
value: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss-nextjs/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type LinkProps = ReactLinkProps & {
internalLinkMatcher?: RegExp;

/**
* Support next/link's prefetch prop.
* Next.js Link prefetch.
*/
prefetch?: NextLinkProps['prefetch'];
};
Expand Down