Comments (2)
All targets must be present in both current page and response for a partial replacement to succeed. If any selector is missing in either, Unpoly will assume the page is in an unexpected state. It will then go through the selectors in up.dom.config.fallbacks
to find an alternative match.
The default for up.dom.config.fallbacks
is ['body']
which is why you're seeing the whole page replaced when .button--load-more
is missing.
The workaround I'm currently using is returning something like this on the last page:
That's how I would implement this. You can hide unwanted margins around the element with a CSS rule like .button--load-more:empty { display: none }
.
Is there a way to set "soft" targets, so if they are missing from the response they get removed instead?
Not currently. I think it's a good idea for a future feature, although we would need to think hard about the expected behavior when an optional target is missing from the response. I think someone could expect three different things:
- Remove the unmatched element from the current page (your expectation)
- Don't change the unmatched element (this is how
[up-hungry]
works) - Empty the content of the unmatched element
One possible issue with removing the unmatched element is that once it's removed, it can no longer match in a future replacement. In your example, if another link wants to go back to page 1 by replacing .news-list, .button--load-more:optional
, we would never get that button back.
from unpoly.
Thanks a lot for the detailed explanation! I'm fine with the workaround.
from unpoly.
Related Issues (20)
- CSP blocking `up.reload` even with `unsafe-eval` HOT 4
- Submit via out-of-form element does not contribute the element name/value pair HOT 2
- DOMException: Failed to execute 'matches' on 'Element': ':none' is not a valid selector. HOT 3
- While in an overlay, Unpoly 3 injects a form fragment outside [up-target] after onBlur validation HOT 6
- Cannot submit form containing a field called "contains" in Unpoly 3 HOT 3
- Allow custom navigation feedback HOT 7
- Redirect to new URL
- Wrong cursor position on up-autosubmit form with field type="number" HOT 1
- Using up.on with the passive option set to true raises an unexpected error HOT 2
- tiny doc opt: new changes accessible on github HOT 1
- Doc: dead link in url-patterns
- up-alias not matching URL query string with asterix after shash HOT 2
- https://unpoly.com/ broken HOT 2
- Little documentation typo: `Sxee` instead of `See`
- nested up-hungry removes inner hungry elements HOT 1
- per page css
- Hide focus ring when following an [up-instant] link HOT 1
- Please support `up.reload(":none")` HOT 3
- Respect unpoly attributes on form submitters HOT 2
- snipcart with unpoly HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unpoly.