Skip to content
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

WordPress script modules API can't be cache-busted, incorrect scripts are cached #587

Closed
ryelle opened this issue Mar 8, 2024 · 2 comments

Comments

@ryelle
Copy link
Contributor

ryelle commented Mar 8, 2024

I unpinned and updated Gutenberg today, and ran into this error again: https://meta.trac.wordpress.org/ticket/7471 — but only on some sites.

After digging, I realized that the JS sent by the server was different on the working/broken sites, and that the broken sites had the previous version's JS cached (even at the new ?ver=17.8.2 URL). Our mid-deploy-cachebuster.php script should be handling this, but unfortunately, the new script modules API does not use the script_loader_src filter.

I tried fixing this quickly with this change — setting the version on a different filter, which did work for the <script type="module" src="… tags. But after deploying that, the issue persisted, because the interactivity/index.min.js file was not using this new cachebuster.

<script type="importmap" id="wp-importmap">
{"imports":{"@wordpress\/interactivity":"https:\/\/wordpress.org\/wp-content\/plugins\/gutenberg\/build\/interactivity\/index.min.js?ver=17.8.1"}}
</script>

We need to be able to update the version in the import map ^ somehow. This is totally unfilterable from my dive into the code. To fix the original nav issue, I ended up rolling back GB to 17.8.1 to force that version to change.

Maybe this should be a core ticket?

@dd32
Copy link
Member

dd32 commented Mar 11, 2024

Maybe this should be a core ticket?

I agree, I've filed something upstream: https://core.trac.wordpress.org/ticket/60742

WP_Script_Modules::get_versioned_src should have a filter. It could re-use script_loader_src for max-compat.

https://github.com/WordPress/wordpress-develop/blob/45ec568f0ce905b9aabfb469b613e39d042ad3b7/src/wp-includes/class-wp-script-modules.php#L337-L348

@dd32
Copy link
Member

dd32 commented Mar 18, 2024

Core has adopted the script_module_loader_src filter, and I've added it to our deploy cache changes.

@dd32 dd32 closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants