-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix unwanted rich previews for internal urls #32613
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
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.
So If I'm not wrong, this feature requires two block-editor settings, It feels a bit too much for just previews tbh. Can't we introduce the bail out behavior inside
__experimentalFetchRemoteUrlDatasomehow?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.
That was my first thought. Should that need to know about the concept of an internal URL though?
I can look into that later on today.
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.
Maybe the block-editor doesn't need to know about "fetchRemoteURL" entirely? I'm just thinking out loud but maybe the setting should be
renderURLPreview(render function)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.
That is an interesting option.
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.
But does it mean that the users have to implement the loading and error status/style by themselves?
How about instead of accepting an async function (fetchRemoteUrlData), or a render function (renderUrlPreview), we simply accept a React hook (useRemoteUrlData) as the setting value? The hook takes a remote
urlas the argument, and returnrichDataandisFetching, just like the one we've already created.This way, the users don't have to implement the loading style, and they can also skip fetching internal URLs if the
urlmatches a certain pattern. There are no intermediate loading status like we have in async function since that everything can return synchronously. In the future, we can also handle errors or support other progressive enhancements directly in the hook.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.
so it would be something like:
this kind of breaks the rules of hooks, because that hook is not necessarily defined and can be updated over time to call different built-in hooks.
I do think it could be nice, but maybe a bit fragile and a bit weird as well (a react hook as a setting).
WDYT
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.
@youknowriad What you have is (I think) how @kevin940726 and I imagined it.
That's probably the biggest problem for me. It's likely to only be defined in the Editor and not the Block Editor.
Uh oh!
There was an error while loading. Please reload this page.
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.
How about we change the setting to
fetchRichDataand remove the current__experimentalFetchRemoteUrlData.This will accept a
urlmuch as__experimentalFetchRemoteUrlDatadoes now. But within the function, we can decide which path to follow based on whether theurlis internal or not.Initially the implementation would be something like:
Then in the future we could bolt on the ability to fetch rich data about an internal URL very easily.
This allows us to keep the current hook implementation the same whilst also making sure that
block-editorhas no idea about WP specific stuff.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.
See #32658
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.
What I was thinking is to split
<LinkPreview>into 2 different components, one is the originalLinkPreview, and the other one is theLinkRichPreviewcomponent. We can skip rendering<LinkRichPreview>if there's nouseRemoteURLData(or any other name) so that we don't break the rules of hooks. And I would imagine the setting can't be updated once it's rendered so that it won't break the other rule of hooks either.But I agree that it's a bit weird though. Maybe render function (or just a component) is a better way to go, but would need to update
LinkPreviewto make it work.