Repository navigation
Enable rich previews for internal links - #33086
Merged
Merged
Conversation
This doesn’t necessarily need to be a remote URL. We could be fetching from an internal URL using the same mechanic so let’s not confuse people/things.
Contributor
Author
|
@hellofromtonya When testing this I've realised that the |
This comment has been minimized.
This comment has been minimized.
getdave
commented
Jul 29, 2021
Comment on lines
+54
to
+73
| if ( ! isURL( url ) ) { | ||
| return Promise.reject( | ||
| new TypeError( `${ url } is not a valid URL.` ) | ||
| ); | ||
| } | ||
|
|
||
| // Test for "http" based URL as it is possible for valid | ||
| // yet unusable URLs such as `tel:123456` to be passed. | ||
| const protocol = getProtocol( url ); | ||
|
|
||
| if ( | ||
| ! isValidProtocol( protocol ) || | ||
| ! protocol.startsWith( 'http' ) || | ||
| ! /^https?:\/\/[^\/\s]/i.test( url ) | ||
| ) { | ||
| return Promise.reject( | ||
| new TypeError( `${ url } does not have a valid protocol.` ) | ||
| ); | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
Moving all the previous URL checking logic into the main function rather than in the intermediary.
getdave
commented
Jul 29, 2021
| const { undo } = useDispatch( editorStore ); | ||
|
|
||
| // Temporary home - should this live in `core-data`? | ||
| const fetchRichUrlData = useCallback( |
Contributor
Author
There was a problem hiding this comment.
This intermediary function is no longer required as we will be allowing rich previews for internal URLs as well as external.
getdave
marked this pull request as ready for review
July 29, 2021 12:27
getdave
requested review from
bph and
kevin940726
and removed request for
ellatrix and
nerrad
July 29, 2021 12:27
Contributor
bph
approved these changes
Jul 29, 2021
bph
left a comment
Contributor
There was a problem hiding this comment.
From a user perspective, this looks feature complete.
talldan
approved these changes
Jul 30, 2021
talldan
left a comment
Contributor
There was a problem hiding this comment.
LGTM, only one really minor comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
This PR enables rich previews in the link UI for internal links. Currently we have a "middleman" method which short-circuits any attempts to fetch rich previews for internal URLs. However based on discussion in #32689 this is not needed as the only thing that originally made me think those requests did not work was the
wp-envenvironment setup.Closes #32689
How has this been tested?
Testing environment
wp-envto test this PR.The best way to test this is on a site that is accessible to the internet or has a local hosts file mapping to ensure traffic can be routed to it. I recommend MAMP or Local by Flywheel (which is now free!).
If you attempt to test this using the default
wp-envsetup onlocalhost:8888then it will not work. That's not a failure of the code, it's just a facet of the way WP ENV and Docker work.Aside: you could use ngrok if using
wp-envbut it's fairly "involved".Awareness of caching
Also when testing this be aware that there are x2 caches involved:
Testing Steps
Site IconunderSite Identity.Note: unfortunately out of the box WP doesn't set a meta description or a reference to the canonical image for the page so we cannot reliably retrieve these items to display in the rich preview. @hellofromtonya any idea why this is? Why don't we set these by default?
Bonus: testing even richer previews!
In order to prove this feature does work if the correct meta data is made available in the page HTML, you can install a SEO Plugin to set these items for you.
Yoast SEO(don't install Yoast as they overide the inline link UI so they won't get rich previews) The SEO Framework Plugin.Screenshots
Out of the box (no SEO Plugin)
Screen.Capture.on.2021-07-29.at.13-24-51.mov
With SEO Plugin
Screen.Capture.on.2021-07-29.at.13-24-01.mp4
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.jsfiles for terms that need renaming or removal).