From 0898ba5e0be5a5b86f660faaea11ee020504c644 Mon Sep 17 00:00:00 2001
From: Illia Kovalenko <23364749+illiakovalenko@users.noreply.github.com>
Date: Tue, 25 Feb 2025 14:20:08 +0200
Subject: [PATCH] PR #2039 adjustments (#2046)
* Added unit tests
* Updated CHANGELOG
---
CHANGELOG.md | 6 ++++-
.../src/components/Link.test.tsx | 22 +++++++++++++++++++
.../src/components/Link.tsx | 2 +-
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 917b3d4bfd..8cbb02f7ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx
index 069deca7fe..0549a1e171 100644
--- a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx
+++ b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx
@@ -165,6 +165,28 @@ describe('', () => {
expect(c.find(ReactLink).length).to.equal(0);
});
+ it('should render with prefetch prop provided', () => {
+ const field = {
+ href: '/lorem',
+ text: 'ipsum',
+ };
+ const c = mount(
+
+
+
+ );
+
+ 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: {
diff --git a/packages/sitecore-jss-nextjs/src/components/Link.tsx b/packages/sitecore-jss-nextjs/src/components/Link.tsx
index f9308d2169..22b9d881bd 100644
--- a/packages/sitecore-jss-nextjs/src/components/Link.tsx
+++ b/packages/sitecore-jss-nextjs/src/components/Link.tsx
@@ -18,7 +18,7 @@ export type LinkProps = ReactLinkProps & {
internalLinkMatcher?: RegExp;
/**
- * Support next/link's prefetch prop.
+ * Next.js Link prefetch.
*/
prefetch?: NextLinkProps['prefetch'];
};