Skip to content

feat(AssetUpdater): re-run view scripts on client navigation - #73

Merged
kidunot89 merged 1 commit into
mainfrom
feat/assetupdater-reinit-bypass
Jun 23, 2026
Merged

feat(AssetUpdater): re-run view scripts on client navigation#73
kidunot89 merged 1 commit into
mainfrom
feat/assetupdater-reinit-bypass

Conversation

@kidunot89

Copy link
Copy Markdown
Collaborator

Summary

AssetUpdater skipped re-inserting already-loaded scripts on client-side navigation, so WordPress view scripts that initialize with the standard document.readyState / DOMContentLoaded ready-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.

  • Scripts now re-execute on every client navigation by default. A re-evaluated script sees readyState === 'complete' and runs its else { init() } branch, re-initializing against the new DOM — no SPA-specific code in the block.
  • New reinitBypassHandles prop lists handles to load once and skip on later navigations, for non-idempotent IIFEs (e.g. wc-order-attribution, whose customElements.define() throws on a second run). Default []; NextPress hardcodes no handle names.
  • Docs updated (docs/api/asset-updater.md): new "Script re-execution on navigation" section, prop table/example, corrected the stale external-dedupe note.

Test plan

  • Navigate client-side to a page with WP view scripts using the readyState/DOMContentLoaded pattern → they re-initialize (no full reload needed).
  • A page with wc-order-attribution in reinitBypassHandles → no NotSupportedError: ... already been used on navigation; the script is not re-run.
  • Hard refresh still initializes scripts as before.
  • instance proxying and bypassDomains (external/CDN URLs) unchanged.

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.
@kidunot89
kidunot89 merged commit 650fbea into main Jun 23, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
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

Successfully merging this pull request may close these issues.

1 participant