add API for response chunks#176
add API for response chunks#176kratiahuja merged 5 commits intoember-fastboot:masterfrom mainmatter:response-chunks
Conversation
…which does not support destructuring and let
| const HTMLSerializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap); | ||
|
|
||
| const SHOEBOX_TAG_PATTERN = '<script type="fastboot/shoebox"'; | ||
| const HTML_HEAD_REGEX = /^([\s\S]*<\/head>)([\s\S]*)/; |
There was a problem hiding this comment.
I'm not sure what you mean - this RegExp does not make any assumptions on how the <body> looks and works perfectly fine with a tag like <body data-foo="my value">.
There was a problem hiding this comment.
@marcoow ah sorry for confusion, my bad - it says head> and I was reading body> 🤦
|
@kratiahuja, @rwjblue: do you have a minute to review? |
|
@marcoow: sorry I have been travelling. I can review it early next week if that isn’t late. |
|
Thanks @kratiahuja! I'm sure your busy so whenever you find the time is great but we'd like to use this from a release version ;) |
| * @returns {Promise<Array<String>>} the application's DOM serialized to HTML, split into chunks | ||
| */ | ||
| chunks() { | ||
| return insertIntoIndexHTML(this._html, this._head, this._body, this._bodyAttributes).then((html) => { |
There was a problem hiding this comment.
@marcoow A minor optimization that can be done here is:
Instead of replacing the entire index.html, you may want to think about only replacing the chunk lazily. This will enable sending the head faster. Can be done at a later point too. I think with streaming you want to make sure you do an early flush as soon as possible.
There was a problem hiding this comment.
Yeah, ideally we could stream the head as soon as it is rendered, even while the rest of the document is still being rendered. My understanding is that that is currently not possible though as we have to wait until visit resolves at which point the complete document has been rendered already? Also I guess in order for that to work we'd have to make this a generator function rather than returning a promise?
Or maybe you're referring to something else that I don't get :)
There was a problem hiding this comment.
Yeah I wasn't refering to waiting for visit. But right now we parsing the entire index.html and replacing body as well when we only want to send the head first.
There was a problem hiding this comment.
Yeah, good point. But I think we'd have to turn this into a generator function then though to be able to give control back to the caller once the first chunk has been calculated. That would be a breaking change though…
|
@marcoow I'll release a new version tonight. |
|
@kratiahuja: awesome - thanks! |
|
@marcoow |
This adds a new method
chunksto theResultclass that returns the HTML in chunks:The idea behind this is that this could be used in e.g. https://github.com/ember-fastboot/fastboot-express-middleware to send a streaming response so that big shoeboxes don't delay the whole document.
closes #174