Skip to content

Commit 5b15e89

Browse files
authored
Fix amp search result links (#125)
* Fix hrefs on search suggestions in AMP. * bump version
1 parent 0db349a commit 5b15e89

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-storefront",
3-
"version": "8.15.0",
3+
"version": "8.15.1",
44
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
55
"module": "./index.js",
66
"license": "Apache-2.0",

src/link/Link.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ const Link = ({ as, href, prefetch, prefetchURL, pageData, onClick, children, ..
6363
</NextLink>
6464
)
6565
} else {
66+
const child = React.Children.only(children)
67+
const passHref = !child.props.href // we only passHref if the child does not have an href prop already. This fixes a bug with AMP where NextLink overrides and escapes amp-bind syntax in hrefs.
68+
69+
// This way we can get a ref of Material-ui components
6670
return (
67-
// This way we can get a ref of Material-ui components
6871
<RootRef rootRef={ref}>
69-
<NextLink href={href} prefetch={false} as={as} passHref>
72+
<NextLink href={href} prefetch={false} as={as} passHref={passHref}>
7073
{React.cloneElement(children, {
7174
onClick: handleClick,
7275
...other,

src/search/SearchSuggestionItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function SearchSuggestionItem({
5757
{children ? (
5858
children
5959
) : (
60-
<a>
60+
<a href={item.as}>
6161
<div data-ui={ui}>
6262
<ImageComponent
6363
className={classes.thumbnail}

0 commit comments

Comments
 (0)