Giter Site home page Giter Site logo

Comments (5)

EverettMcKay avatar EverettMcKay commented on August 26, 2024 2

Using a key is in fact the problem. It looks like I do need a key, but not for the part that scrolls. Removing the key from that fixed the problem.

Thanks, @cavemansspa and @osban!

from mithril.js.

cavemansspa avatar cavemansspa commented on August 26, 2024

hello @EverettMcKay, typically that should re-render in place. here's an example

if you can provide an example of your issue, we can advise.

from mithril.js.

EverettMcKay avatar EverettMcKay commented on August 26, 2024

Ok, thanks. My component basically boils down to this:

export const FhExample = () => ({
  tag: "Example",
  attrs: () => {},
  state: () => {},
  view: () => (
    <>
      <h1>Example</h1>
      <div style="padding:8px 0;width:100%">
        <div key={key} class="card" style="padding:8px 16px;margin:8px 8px">
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
          <SelectOption condition={show based on state} attrs />
        </div>
      </div>
    </>
  ),
});

The various options are displayed based on the current state. If the state changes, I increment the key to force a redraw.

Works great until the you scroll. Any redraw undoes the scroll.

from mithril.js.

cavemansspa avatar cavemansspa commented on August 26, 2024

changing the key will result in a full remove / replace, so that is likely resulting in the scroll reset. if you can reproduce the issue in a flems, we can have a closer look.

from mithril.js.

osban avatar osban commented on August 26, 2024

I agree with @cavemansspa. Using the autoredraw (and diff) of Mithril or m.redraw() (depending on how you deal with the state changes) should keep the scroll position. You might also want to either pass the state and such as attrs if it's external (deconstructing is possible: view: ({attrs: {tag, state, ...rest}}) =>), or use the outer function of the closure you're using in case of internal state.

from mithril.js.

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.