~repos /edge-city

#react#js#ssr

git clone https://pyrossh.dev/repos/edge-city.git

edge-city is a next level meta-framework for react that runs only on edge runtimes


8ef8a7ec Peter John

2 years ago
Fix duplicate css dom nodes
Files changed (1) hide show
  1. packages/parotta/router.js +17 -7
packages/parotta/router.js CHANGED
@@ -112,17 +112,27 @@ export const Router = ({ App, history, radixRouter }) => {
112
112
  const [match, setMatch] = useState(() => getMatch(radixRouter, history.location.pathname));
113
113
  useEffect(() => {
114
114
  return history.listen(({ location }) => {
115
+ const href = getCssUrl(location.pathname);
116
+ const isLoaded = Array.from(document.getElementsByTagName("link"))
117
+ .map((link) => link.href.replace(window.origin, "")).includes(href);
118
+ if (!isLoaded) {
115
- var link = document.createElement('link');
119
+ const link = document.createElement('link');
116
- link.setAttribute("rel", "stylesheet");
120
+ link.setAttribute("rel", "stylesheet");
117
- link.setAttribute("type", "text/css");
121
+ link.setAttribute("type", "text/css");
118
- link.onload = () => {
122
+ link.onload = () => {
123
+ nProgress.start();
124
+ startTransition(() => {
125
+ setMatch(getMatch(radixRouter, location.pathname));
126
+ })
127
+ };
128
+ link.setAttribute("href", href);
129
+ document.getElementsByTagName("head")[0].appendChild(link);
130
+ } else {
119
131
  nProgress.start();
120
132
  startTransition(() => {
121
133
  setMatch(getMatch(radixRouter, location.pathname));
122
134
  })
123
- };
135
+ }
124
- link.setAttribute("href", getCssUrl(location.pathname));
125
- document.getElementsByTagName("head")[0].appendChild(link);
126
136
  });
127
137
  }, [])
128
138
  console.log('Router');