-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add service worker streaming #85
Changes from 1 commit
c4c5d13
7b8e0bf
fcec82a
6ae18b2
348840f
85e2efd
e7e4522
baf00f1
52a71f6
992f479
720d187
ba3b3a4
1811ec9
2f760b6
293bfdb
831bcb6
16852cf
0e6985a
51fd288
9855b53
9bfe7cc
3b11698
7da958d
270ab2c
65d74ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,16 @@ wp.serviceWorker.routing.registerRoute( new wp.serviceWorker.routing.NavigationR | |
|
||
const handleResponse = ( response ) => { | ||
if ( response.status < 500 ) { | ||
return response; | ||
if ( response.redirected ) { | ||
const redirectedUrl = new URL( response.url ); | ||
redirectedUrl.searchParams.delete( STREAM_HEADER_FRAGMENT_QUERY_VAR ); | ||
const script = `<script>history.replaceState( {}, '', ${ JSON.stringify( redirectedUrl.toString() ) } );</script>`; | ||
return response.text().then( ( body ) => { | ||
return new Response( script + body ); | ||
} ); | ||
} else { | ||
return response; | ||
} | ||
} | ||
const channel = new BroadcastChannel( 'wordpress-server-errors' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker at this point, but it would be needed to define the scenario for browsers that do not support BroadcastChannel (https://caniuse.com/#search=broadcastchannel) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is captured in #81. |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffposnick here's how I ended up dealing with the challenge of handling a streamed body that redirects.
The “Try Redirect” nav menu item points to an old post URL that redirects, so you can see the URL go from "old-post" to "new-post".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Demo site: https://streaming-westonruter.pantheonsite.io/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍