prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

PrismicLink incorrectly defaulting with target _blank in rich text field #171

Closed greatwitenorth closed 1 year ago

greatwitenorth commented 1 year ago

Versions

Reproduction

Minimum reproduction can be found here: https://github.com/greatwitenorth/roadmap-link-issue

Screen Shot 2023-01-23 at 11 29 09 AM Screen Shot 2023-01-23 at 11 29 53 AM

repo is roadmap-link-issue

At some point between v2.0.3 (the last known version which was working for me) and v2.5.1 it looks like a decision was made to open external links in a new window by default if no target has been specified. This produces undesirable behaviour, since when a rich text field contains a link, no target is generally specified if you want the link to open in the same window.

It seems like this block of code might be contributing to the problem: https://github.com/prismicio/prismic-react/blob/5b49ad5f9b624ed843c44f28dc3063ae8cde4bd0/src/PrismicLink.tsx#L187-L194

Steps to reproduce

What is expected?

What is actually happening?

angeloashmore commented 1 year ago

Hey @greatwitenorth, thanks for the report!

You're correct; <PrismicLink> was updated in v2.4.0 to automatically open external URLs in new windows. In retrospect, this was a mistake for the exact reason you explained.

The change has been revered as of v2.5.2. target="_blank" is now only automatically set if "Open in new tab" is checked.

You can install the latest version of @prismicio/react with the following command:

npm install --save @prismicio/react@latest

If this doesn't fix the issue, please let me know and I'll take another look at it. Thanks! 🙂