Repository navigation
fix: Keep page styles intact when filters navigate, and document the offset gotcha - #84
Merged
Merged
Conversation
…offset gotcha
After a filter changed, content after the Query Loop lost its styling until
reload. Two causes, both in how the Interactivity API router swaps a region:
- Block style variation (is-style-{name}--{n}) and element (wp-elements-{n})
classes are numbered in render order. A different result count shifted the
numbers, so markup after the loop no longer matched the new page's CSS.
Each Query block now reserves 1,000 of these numbers.
- The router disables stylesheets missing from the fetched HTML, including
styles injected by scripts (e.g. the WPForms honeypot CSS). view.js now
re-enables id-less styles present before the router loaded, after each
navigation and on back/forward.
Also adds a README troubleshooting entry: a Query Loop offset applies after
the filter, so it can hide a term's only post.
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.
Problem
On a page with a Query Filter (reproduced on a local site at
/insights/), changing a filter broke the styling of everything after the Query Loop until reload: eyebrow headings, a teal card, footer headings, link colours, and a WPForms honeypot field became visible ("Email Email Email").Causes
Both come from how the Interactivity API router swaps a router region: it replaces the region's markup, but applies the fetched page's stylesheets to the whole document.
is-style-{name}--{n},wp_unique_id()) and element styles (wp-elements-{n},wp_unique_prefixed_id()) number their classes in render order. A different result count shifts every number after the loop, so the markup kept outside the region no longer matches the new CSS. Core fixed the same problem for layout classes by switching to hashes (Layout styles are incompatible with Interactivity API client-side navigation WordPress/gutenberg#67308); these two are still counters in WP 7.1.Fix
BlockFilters::reserve_unique_ids()(render_block_data) records both counters when acore/queryblock starts rendering.render_block_query()then advances them to start + 1,000, so blocks after the loop get the same numbers whatever it rendered. Class numbers after a Query Loop are now higher than before (e.g.is-style-eyebrow--2011).view.jsroutes every navigation through onenavigate()helper. Before the router first loads, it remembersid-less<style>/ stylesheet<link>elements (WordPress gives every stylesheet it prints anid), then re-enables them after each navigation and onpopstate. This covers filters, sort and search.Verification
a11y-speakannouncerKnown limits
id-less<style>that the server prints differently per page would keep its old copy enabled.🤖 Generated with Claude Code
https://claude.ai/code/session_017jLNdSqi2eRVWCyTfQMGy7