-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Legacy widget's preview functionality is broken when the page is moved #34384
Merged
kevin940726
merged 23 commits into
WordPress:trunk
from
anton-vlasenko:fix/use-rest-api-endpoint-for-legacy-widget-preview
Aug 31, 2021
Merged
Legacy widget's preview functionality is broken when the page is moved #34384
kevin940726
merged 23 commits into
WordPress:trunk
from
anton-vlasenko:fix/use-rest-api-endpoint-for-legacy-widget-preview
Aug 31, 2021
Conversation
This file contains 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
anton-vlasenko
requested review from
ajitbohra,
nerrad,
noisysocks and
ntwb
as code owners
August 30, 2021 12:52
…iew was loaded. 2. Refactor the function. Use return early approach.
2. Add error handling. 3. Abort request if the iframe is unmounted. 4. Use useEffect to make a request (per kevin940726's comment). 5. Use states instead of manipulating DOM values.
…dability. 2. Remove isPreviewFetched state (useEffect is enough). 3. Add idBase and instance as dependencies to useEffect method. We have to fetch the preview html again if any of those parameter gets changed. 4. Move abortController and fetchPreviewHTML inside the useEffect callback to avoid recreating them on each component redraw.
… error message can't be minified.
2. Fix code style.
2. Fix code style.
We have to include id_base parameter.
We don't use it.
7 tasks
kevin940726
approved these changes
Aug 31, 2021
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 👍
anton-vlasenko
added
the
[Block] Legacy Widget
Affects the Legacy Widget Block - used for displaying Classic Widgets
label
Aug 31, 2021
@kevin940726 Could you please merge it if you think it's fine? 🙏 |
Nice work 👏 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Block] Legacy Widget
Affects the Legacy Widget Block - used for displaying Classic Widgets
[Type] Bug
An existing feature does not function as intended
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
Legacy Widget block has a preview function. However, it uses a relative URL.
iframe
cannot load the widgets.php file when the code is no longer running from the /wp-admin/ URL.This PR fixes that by using a REST API endpoint instead of the widgets.php file to fetch preview HTML. It doesn't depend on the admin URL.
Fixes #30049
Based on #34230
How has this been tested?
Legacy Widget
block.Meta
widget from the dropdown.Meta
widget itself). You should see a preview of theMeta
widget now.<iframe />
element with thewp-block-legacy-widget__edit-preview-iframe
class. Check itssrcdoc
attribute.Expected result:
The
srcdoc
attribute of the<iframe />
should contain html code of the preview.Please see the screenshots section for reference.
Screenshots
Types of changes
Bug fix.
Checklist:
*.native.js
files for terms that need renaming or removal).