@webqit/webflo 0.10.2 → 0.10.3

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
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "0.10.2",
15
+ "version": "0.10.3",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -88,7 +88,7 @@ export default class Runtime {
88
88
  // Needed to allow window.document.location
89
89
  // to update to window.location
90
90
  window.setTimeout(() => {
91
- this.go(Url.copy(window.document.location), { src: window.document.location, srcType: 'history', });
91
+ this.go(Url.copy(window.document.location), {}, { src: window.document.location, srcType: 'history', });
92
92
  }, 0);
93
93
  });
94
94
 
@@ -72,14 +72,25 @@ export default class Worker {
72
72
 
73
73
  // -------------
74
74
  // ONFETCH
75
- self.addEventListener('fetch', async evt => {
75
+ self.addEventListener('fetch', event => {
76
76
  // URL schemes that might arrive here but not supported; e.g.: chrome-extension://
77
- if (!evt.request.url.startsWith('http')) return;
78
- const deriveInit = req => [
79
- 'method', 'headers', 'body', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
80
- ].reduce((init, prop) => ({ [prop]: prop === 'body' && !req.body ? req : req[prop], ...init }), {});
81
- const requestInit = deriveInit(evt.request.clone());
82
- evt.respondWith(this.go(evt.request.url, requestInit, { event: evt }));
77
+ if (!event.request.url.startsWith('http')) return;
78
+ event.respondWith((async (req, evt) => {
79
+ const requestInit = [
80
+ 'method', 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
81
+ ].reduce((init, prop) => ({ [prop]: req[prop], ...init }), {});
82
+ if (!['GET', 'HEAD'].includes(req.method)) {
83
+ requestInit.body = await req.text();
84
+ }
85
+ // Now, the following is key:
86
+ // The browser likes to use "force-cache" for "navigate" requests, when, e.g: re-entering your site with the back button
87
+ // Problem here, force-cache forces out JSON not HTML as per webflo's design.
88
+ // So, we detect this scenerio and avoid it.
89
+ if (req.cache === 'force-cache'/* && req.mode === 'navigate' - even webflo client init call also comes with that... needs investigation */) {
90
+ requestInit.cache = 'default';
91
+ }
92
+ return this.go(req.url, requestInit, { event: evt });
93
+ })(event.request, event));
83
94
  });
84
95
 
85
96
  // ---------------
@@ -115,7 +126,7 @@ export default class Worker {
115
126
  let httpEvent = new HttpEvent(request, detail, (id = null, persistent = false) => this.getSession(httpEvent, id, persistent));
116
127
  httpEvent.port.listen(message => {
117
128
  if (message.$type === 'handler:hints' && message.session) {
118
- // TODO: Sync sesseion data from client
129
+ // TODO: Sync session data from client
119
130
  return Promise.resolve();
120
131
  }
121
132
  });
@@ -132,20 +143,7 @@ export default class Worker {
132
143
  }
133
144
 
134
145
  // Generates request object
135
- async generateRequest(href, init) {
136
- // Now, the following is key:
137
- // The browser likes to use "force-cache" for "navigate" requests
138
- // when, for example, the back button was used.
139
- // Thus the origin server would still not be contacted by the self.fetch() below, leading to inconsistencies in responses.
140
- // So, we detect this scenerio and avoid it.
141
- if (init.mode === 'navigate' && init.cache === 'force-cache') {
142
- init = { ...init, cache: 'default' };
143
- }
144
- if (init.method === 'POST' && init.body instanceof self.Request) {
145
- init = { ...init, body: await init.body.text(), };
146
- } else if (['GET', 'HEAD'].includes(init.method.toUpperCase()) && init.body) {
147
- init = { ...init, body: null };
148
- }
146
+ generateRequest(href, init) {
149
147
  let request = new Request(href, init);
150
148
  return request;
151
149
  }