@ecopages/browser-router 0.2.0-beta.17 → 0.2.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/browser-router",
3
- "version": "0.2.0-beta.17",
3
+ "version": "0.2.0-beta.19",
4
4
  "description": "Client-side router for Ecopages with view transitions support",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -35,7 +35,7 @@
35
35
  "morphdom": "^2.7.8"
36
36
  },
37
37
  "peerDependencies": {
38
- "@ecopages/core": "0.2.0-beta.17"
38
+ "@ecopages/core": "0.2.0-beta.19"
39
39
  },
40
40
  "types": "./src/index.d.ts"
41
41
  }
@@ -1,4 +1,4 @@
1
- import { isHtmlPageResponse } from "@ecopages/core/router/link-navigation-policy";
1
+ import { assertHtmlPageResponse } from "@ecopages/core/router/link-navigation-policy";
2
2
  async function fetchNavigationPage(url, signal, options = {}) {
3
3
  if (!options.bypassCache && options.getCachedHtml) {
4
4
  const cachedHtml = options.getCachedHtml(url.href);
@@ -16,11 +16,7 @@ async function fetchNavigationPage(url, signal, options = {}) {
16
16
  if (!response.ok) {
17
17
  throw new Error(`Failed to fetch page: ${response.status}`);
18
18
  }
19
- if (!isHtmlPageResponse(response)) {
20
- throw new Error(
21
- `Expected HTML page response, received ${response.headers.get("Content-Type") ?? "unknown content type"}`
22
- );
23
- }
19
+ await assertHtmlPageResponse(response);
24
20
  return response.text();
25
21
  }
26
22
  export {
@@ -1,4 +1,4 @@
1
- import { isHtmlPageResponse, shouldPrefetchLink } from "@ecopages/core/router/link-navigation-policy";
1
+ import { assertHtmlPageResponse, shouldPrefetchLink } from "@ecopages/core/router/link-navigation-policy";
2
2
  import { discoverNewStylesheetLinks, getCurrentStylesheetHrefs } from "../dom/stylesheet-discovery.js";
3
3
  const DEFAULT_PREFETCH_OPTIONS = {
4
4
  strategy: "intent",
@@ -70,10 +70,11 @@ class PrefetchManager {
70
70
  headers: { Accept: "text/html" },
71
71
  priority: "low"
72
72
  });
73
- if (!response.ok || !isHtmlPageResponse(response)) {
73
+ if (!response.ok) {
74
74
  this.prefetched.delete(url.href);
75
75
  return;
76
76
  }
77
+ await assertHtmlPageResponse(response);
77
78
  const html = await response.text();
78
79
  this.htmlCache.set(url.href, html);
79
80
  await this.prefetchStylesheets(html, url);
@@ -123,7 +124,12 @@ class PrefetchManager {
123
124
  headers: { Accept: "text/html" },
124
125
  priority: "low"
125
126
  }).then(async (response) => {
126
- if (!response.ok || !isHtmlPageResponse(response)) {
127
+ if (!response.ok) {
128
+ return null;
129
+ }
130
+ try {
131
+ await assertHtmlPageResponse(response);
132
+ } catch {
127
133
  return null;
128
134
  }
129
135
  return response.text();