Coder Social home page Coder Social logo

hydra-fragments's People

Contributors

dirkdeyne avatar

Watchers

 avatar  avatar

hydra-fragments's Issues

Issue research

When clicking the button, you see empty attributes in the JS. This is because, when adding fragments to the page, it's comparing two empty strings to each other as "lastRenderedHTML". There's no diffs, so its generating empty lists.

This does not occur when no fragments are present or when you're loading fragments locally, because hydraconnectioncontroller#askHydraForFragment has a shortcut that provides an instant response. In the scenario of an actual fragment being loaded from a different instance, there's no instance response but a slightly delayed one due to the wait for a hydra REST call to complete. The rest call itself is not the problem, but the additional delay explains the difference in behavior.

It also means that the cause of the error happens at render already, even though the render itself visually looks ok. Behind the scenes, the session is loaded with an empty 'lastRenderedHTML' meaning that any future changes are compared to an empty string, causing wrong attributes to be loaded.

So, specifically, the problem is here:
https://github.com/medusa-ui/medusa/blob/eeb1c2e9cb171dc7c2901bdd1ea1f87239d2bf5d/medusa-ui/src/main/java/io/getmedusa/medusa/core/router/action/SocketHandler.java#L81-L84

Essentially, the final Flux<DataBuffer> dataBufferFlux = renderer.render(route.getTemplateHTML(), s); only works with immediate responses. When the Flux can actually have a delay -- because for example, it's a REST call with network latency -- then the s.setLastRenderedHTML(newHtml); resolves before the Flux completes, causing the empty string.

One way to fix it would be something like:

final Flux<DataBuffer> dataBufferFlux = renderer.render(route.getTemplateHTML(), s);
dataBufferFlux.subscribe(buffer -> {
    final String oldHTML = s.getLastRenderedHTML();
    final String newHtml = FluxUtils.dataBufferToString(buffer);
    s.setLastRenderedHTML(newHtml);
    sessionMemoryRepository.store(s);

    //run diff engine old HTML vs new
    s.getSink().push(mergeDiffs(diffEngine.calculate(oldHTML, newHtml), passThroughAttributes));
    s.setDepth(0);
});

But it doesn't render right on action yet

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.