feat(AssetUpdater): re-run view scripts on client navigation - #73
Merged
Conversation
Re-execute WordPress view scripts on every client-side navigation so scripts using the standard document.readyState / DOMContentLoaded ready-check re-initialize for the new page's content — no SPA-specific code needed in the block. Add a `reinitBypassHandles` prop to opt non-idempotent scripts (e.g. wc-order-attribution, whose customElements.define throws on a second run) out of re-running; they load once and are skipped thereafter.
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AssetUpdaterskipped re-inserting already-loaded scripts on client-side navigation, so WordPress view scripts that initialize with the standarddocument.readyState/DOMContentLoadedready-check never re-ran for the new page — block view scripts (price, loading skeletons, add-to-cart links, etc.) stayed in their initial state until a full reload.readyState === 'complete'and runs itselse { init() }branch, re-initializing against the new DOM — no SPA-specific code in the block.reinitBypassHandlesprop lists handles to load once and skip on later navigations, for non-idempotent IIFEs (e.g.wc-order-attribution, whosecustomElements.define()throws on a second run). Default[]; NextPress hardcodes no handle names.docs/api/asset-updater.md): new "Script re-execution on navigation" section, prop table/example, corrected the stale external-dedupe note.Test plan
readyState/DOMContentLoadedpattern → they re-initialize (no full reload needed).wc-order-attributioninreinitBypassHandles→ noNotSupportedError: ... already been usedon navigation; the script is not re-run.instanceproxying andbypassDomains(external/CDN URLs) unchanged.