dirkdeyne / hydra-fragments Goto Github PK
View Code? Open in Web Editor NEWserving fragments through Hydra
serving fragments through Hydra
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.