| 272 | } |
| 273 | |
| 274 | function fetchStyleSheet(href: string): Promise<RouteStyleSheet> { |
| 275 | let prom: Promise<RouteStyleSheet> | undefined = styleSheets.get(href) |
| 276 | if (prom) { |
| 277 | return prom |
| 278 | } |
| 279 | |
| 280 | styleSheets.set( |
| 281 | href, |
| 282 | (prom = fetch(href, { credentials: 'same-origin' }) |
| 283 | .then((res) => { |
| 284 | if (!res.ok) { |
| 285 | throw new Error(`Failed to load stylesheet: ${href}`) |
| 286 | } |
| 287 | return res.text().then((text) => ({ href: href, content: text })) |
| 288 | }) |
| 289 | .catch((err) => { |
| 290 | throw markAssetError(err) |
| 291 | })) |
| 292 | ) |
| 293 | return prom |
| 294 | } |
| 295 | |
| 296 | return { |
| 297 | whenEntrypoint(route: string) { |