Skip to content

Commit

Permalink
Merge pull request #52 from dsyer/main
Browse files Browse the repository at this point in the history
Use caching response wrapper in case views render pre-emptively
  • Loading branch information
wimdeblauwe authored Jul 28, 2023
2 parents 678c9fb + ed935f2 commit f4998bd
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.util.Assert;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.*;
import org.springframework.web.util.ContentCachingResponseWrapper;

import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -130,11 +131,13 @@ private View toView(HtmxResponse partials) {

return (model, request, response) -> {
Locale locale = locales.getObject().resolveLocale(request);
ContentCachingResponseWrapper wrapper = new ContentCachingResponseWrapper(response);
for (String template : partials.getTemplates()) {
View view = views.resolveViewName(template, locale);
Assert.notNull(view, "Template '" + template + "' could not be resolved");
view.render(model, request, response);
view.render(model, request, wrapper);
}
wrapper.copyBodyToResponse();
};
}
}

0 comments on commit f4998bd

Please sign in to comment.