Skip to content

Commit

Permalink
fix(router): until directive breaks haunted effects
Browse files Browse the repository at this point in the history
The haunted state is updated twice in the same update-render-loop, causing the scheduler to miss running the effects upon component initialization.
  • Loading branch information
cristinecula authored and nomego committed May 14, 2020
1 parent 958dfa9 commit 951e886
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cosmoz-page-router.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {
nothing, html
nothing,
html
} from 'lit-html';
import { until } from 'lit-html/directives/until';
import {
component, useMemo
component,
useMemo
} from 'haunted';
import {
useRoutes
} from './lib/use-routes';
import { useRoutes } from './lib/use-routes';
import { useRouteEvents } from './lib/use-route-events';
import { usePromise } from '@neovici/cosmoz-utils/lib/hooks/use-promise';

const Router = function ({
routes
}) {
const route = useRoutes(routes),
result = useMemo(() => route ? route.handle() : undefined, [route]),
renderResult = useMemo(() => Promise.resolve(result).catch(() => nothing), [result]);
renderResult = useMemo(() => Promise.resolve(result).catch(() => nothing), [result]),
[output] = usePromise(renderResult);

useRouteEvents(route, result, this);

return html`${until(renderResult, nothing)}`;
return html`${output || nothing}`;
};

customElements.define('cosmoz-page-router', component(Router));
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
}
},
"dependencies": {
"@neovici/cosmoz-utils": "^3.4.0",
"@polymer/iron-location": "^3.0.0",
"@polymer/polymer": "^3.3.1",
"haunted": "^4.7.0",
Expand Down

0 comments on commit 951e886

Please sign in to comment.