Giter VIP home page Giter VIP logo

Comments (2)

triskweline avatar triskweline commented on May 28, 2024 1

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.

bummzack avatar bummzack commented on May 28, 2024

Thanks a lot for the detailed explanation! I'm fine with the workaround.

from unpoly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.