-
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 #34184
Legacy widget's preview functionality is broken when the page is moved #34184
Conversation
@anton-vlasenko You can target the base branch to #34230's branch so that it won't show the commits from that PR. Just have to remember to rebase to trunk once it's merged :). |
That's a good idea. I tried to do it as you said and I got this popup message: |
@anton-vlasenko I believe you just have to remove the commits that's already on that branch and rebase your branch onto that. |
…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.
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.
Code LGTM 👍. We need to wait for #34230 before merging this though, or just merge this onto that branch.
09a1d67
to
c6b6664
Compare
This PR has been closed by GitHub (unintentionally). |
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).