Skip to content

Commit

Permalink
perf(plugin): improve error message in Link component
Browse files Browse the repository at this point in the history
  • Loading branch information
mohatt committed Jul 30, 2021
1 parent bb91a5a commit 0ebdfa5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/src/templates/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const AboutTemplate = ({ data: { page } }) => (
<Layout title={page.title}>
<div className="row">
<div className="col-md-3">
<img className="card-img" src="http://placehold.it/100x200" alt="" />
<img className="card-img" src="//via.placeholder.com/100x200" alt="" />
</div>
<div className="col-md-9">
<div>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const Link = ({ to, params, scope, ...props }) => {
try {
to = generatePath(to, params, scope, true)
} catch (e) {
console.error(
'Warning: Invalid route params supplied to `Link` component: ' + e.message
)
if (process.env.NODE_ENV !== 'production') {
console.error(`gatsby-plugin-advanced-pages: Unable to generate path for route "${to}": ${e.message}`)
}
to = '/404.html'
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/__snapshots__/Link.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Array [
exports[`<Link /> should log console error when called with invalid props 2`] = `
Array [
Array [
"Warning: Invalid route params supplied to \`Link\` component: Error generating a path for route \\"/blog/post/:post\\" with params \\"{}\\": Expected \\"post\\" to be a string",
"gatsby-plugin-advanced-pages: Unable to generate path for route \\"blog.post\\": Error generating a path for route \\"/blog/post/:post\\" with params \\"{}\\": Expected \\"post\\" to be a string",
],
]
`;

exports[`<Link /> should log console error when called with invalid props 3`] = `
Array [
Array [
"Warning: Invalid route params supplied to \`Link\` component: Error generating a path for route \\"/blog/post/:post\\" with params \\"{\\"invalid\\":\\"whatever\\"}\\": Expected \\"post\\" to be a string",
"gatsby-plugin-advanced-pages: Unable to generate path for route \\"blog.post\\": Error generating a path for route \\"/blog/post/:post\\" with params \\"{\\"invalid\\":\\"whatever\\"}\\": Expected \\"post\\" to be a string",
],
]
`;
Expand Down

0 comments on commit 0ebdfa5

Please sign in to comment.