Yesod: using widget twice in duplicates of Julius widget

I have a Yesod widget that loads the widget twice. The "main" widget looks like this:

<div .container-fluid .hidden-xs>
  <div .row .no-gutter>
    <div .col-sm-3>
      <!-- sidebar content -->
    <div .col-sm-9>
      <!-- the widget i'm loading twice -->
      ^{dashboardMain}
<nav .visible-xs>
  <!-- sidebar content, also loaded twice, but this widget isn't causing problems (yet) -->
<div .container .visible-xs>
  <div .row .no-gutter>
    ^{dashboardMain}

I'm having problems because the Julius file for my argument is dashboardMaindownloaded and compiled twice. Yesod merges two copies of my Julius file. This upsets the situation elsewhere.

My Haskell code looks like this:

crmSidebar :: Widget
crmSidebar = defaultSidebarItems -- Using Knockout and a convention based "api"

crmApp :: Widget
crmApp = $(widgetFile "app/crm")

getCRMDashboardR :: Handler TypedContent
getCRMDashboardR = selectRep . provideRep . defaultLayout $ dashboardLayout crmSidebarItems crmApp

Haskell compiles fine, but as I said, I get a Javascript error at runtime due to the way Yesod / Julius handles my widget. What should I do?


Edit 1:

I use KnockoutJS, which requires it to be ko.applyBindings(viewModel)applied exactly once. Changing this setting is not an option.

dashboardLayout determined by

dashboardLayout :: String -> Widget -> Widget -> Widget
dashboardLayout sidebarHeader dashboardSidebarItems dashboardMain = $(widgetFile "layouts/dashboard")
+4
source share

Source: https://habr.com/ru/post/1694943/


All Articles