-
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
Block Directory: Use local assets with automatic asset detection #24117
Conversation
This is working well for the blocks I've tried, including some blocks we had other issues with. The only edge case I've found so far is if you install a block, remove it from the page & save (so it uninstalls the block), then try to re-add it, the scripts are technically still on the page, so it's not loaded back in. I think that's sufficiently edge-case, but still wanted to flag it (that whole uninstall-unused-blocks flow is awkward, we'll probably want to revisit that with 5.6 too) |
As long as the scripts are still loaded, skipping inserting them again and proceeding with the block insertion should work, right? |
Well, the block gets unregistered on uninstall, so it would need to be registered again, which is done in the plugin's JS. and if we don't unregister it, it stay in the block library as if it still exists. |
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 looks good, just a couple minor comments below.
The e2e tests are failing and I can reproduce the failure locally by running THROTTLE_CPU=4 npm run test-e2e packages/e2e-tests/specs/editor/plugins/block-directory-add.test.js
. Perhaps something like await page.waitForSelector
here instead of a timeout might fix it?
I tested in Spanish using simple-iframe
and verified it loaded the correct version right away, whereas without this change it first loads the English version. Also tried block-a-saurus
but it's still loading the English version. embed-block-for-github
is also still loading in English and the first time I tried it there was a PHP error on the page (which I stupidly didn't screenshot and haven't been able to reproduce since; hopefully it's nothing).
…ons and other <script> elements by requesting the current page in the background and comparing the loaded assets.
… than being entirely async
36e4679
to
6e18053
Compare
Unfortunately this wasn't easy to fix, I've worked around it previously in https://github.com/WordPress/block-directory-e2e/blob/master/specs/block-directory.test.js#L104-L108 by adding a networkIdle implementation that waits until all resources are loaded.
Unfortunately, WordPress doesn't install translations when Blocks are installed at present. WordPress/wordpress-develop#427 is pending for that.
Any chance that might be in some error logs somewhere? I'm not sure how/what/why that could've been.. |
Managed to reproduce the error again when I reopened the post I had added the GitHub block to in a new tab:
Regarding the e2e test, I reckon it's worth trying the |
Awesome, thanks! It doesn't appear to be inserted into the post from this code, but it will appear pre-post-render on development setups, not much we can do about plugin notices. Shouldn't be seen in production.
That's what I figured, I was hoping there'd be a simpler approach as I didn't really want to add request-interception for all tests unless it's already in use somewhere (I don't know much about e2e testing, other than having spent far too long debugging this exact problem). @StevenDufresne Do you have any ideas? |
Yep, since we are mocking all the requests, waiting for the |
…the block install, and wait for the block to be inserted rather than usin a delay.
I misunderstood how these tests were running, and how it mocked requests, I believe 042dfd5 will handle this appropriately. |
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.
Everything's looking good— I tried a bunch of ways I could think of to break things, intentionally triggering fatal errors once the plugin is installed, that sort of thing, and it never broke the editor. We could definitely improve some of the UX in errors, but that's tracked in #23733.
Can we remove |
IMHO Yes, however, it seems likely that it would be re-implemented for WP 5.6 - probably with a different schema though - for making use of |
Ok, I'm going to drop it then. |
Description
Use a XHR request to the post edit screen to detect what Script/Style assets to insert into the page after Block Installs.
This resolves translations not loading for installed Blocks, and blocks that don't currently load all of the required assets.
See https://core.trac.wordpress.org/ticket/50732#comment:6 for background
How has this been tested?
Manual testing. Installing blocks, making sure things work as expected.
Screenshots
Types of changes
Checklist: