-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable rich previews for internal links #33086
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.
@hellofromtonya When testing this I've realised that the |
This comment has been minimized.
This comment has been minimized.
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.` ) | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving all the previous URL checking logic into the main function rather than in the intermediary.
@@ -76,54 +66,6 @@ function useBlockEditorSettings( settings, hasTemplate ) { | |||
|
|||
const { undo } = useDispatch( editorStore ); | |||
|
|||
// Temporary home - should this live in `core-data`? | |||
const fetchRichUrlData = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This intermediary function is no longer required as we will be allowing rich previews for internal URLs as well as external.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a user perspective, this looks feature complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only one really minor comment
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-env
environment setup.Closes #32689
How has this been tested?
Testing environment
wp-env
to 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-env
setup onlocalhost:8888
then 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-env
but it's fairly "involved".Awareness of caching
Also when testing this be aware that there are x2 caches involved:
Testing Steps
Site Icon
underSite 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.js
files for terms that need renaming or removal).