Skip to content

Commit 37d1f21

Browse files
committed
Allow enviroment set _renderMode to be used in Visit
This is part of an arching plan to introduce Glimmer's rehydration/serializtion modes to Ember proper. There are 4 PR's that are all interwoven, of which, this is one. - [ ] Glimmer.js: glimmerjs/glimmer-vm#783 (comment) - [ ] Ember.js: emberjs/ember.js#16227 - [ ] Fastboot: ember-fastboot/fastboot#185 - [ ] EmberCLI Fastboot: #580 In order of need to land they are: Glimmer.js: glimmerjs/glimmer-vm#783 (comment) This resolves a rather intimate API problem. Glimmer-vm expects a very specific comment node to exist to know whether or not the rehydration element builder can do it's job properly. If it is not found on the first node from `rootElement` it throws. In fastboot however we are certain that there will already be existant elements in the way that will happen before rendered content. This PR just iterates through the nodes until it finds the expected comment node. And only throws if it never finds one. --- Ember.js: emberjs/ember.js#16227 This PR modifies the `visit` API to allow a private _renderMode to be set to either serialize or rehydrate. In SSR environments the assumption (as it is here in this fastboot PR) is that we'll set the visit API to serialize mode which ensures glimmer-vm's serialize element builder is used to build the API. The serialize element builder ensures that we have the necessary fidelty to rehydrate correctly and is mandatory input for rehydration. --- Fastboot: ember-fastboot/fastboot#185 This allows enviroment variable to set _renderMode to be used in Visit API. Fastboot must send content to browser made with the serialization element builder to ensure rehydration can be sucessful. --- EmberCLI Fastboot: #580 Finally this does the fun part of disabling the current clear-double-render instance-initializer We first check to ensure we are in a non-fastboot environment. Then we ensure that we can find the expected comment node from glimmer-vm's serialize element builder. This ensures that this change will only effect peoeple who use ember-cli-fastboot with the serialized output from the currently experimental fastboot setup Then we ensure `ApplicationInstance#_bootSync` specifies the rehydrate _renderMode. This is done in `_bootSync` this way because visit is currently not used to boot ember applications. And we must instead set bootOptions this way instead. We also remove the markings for `fastboot-body-start` and `fastboot-body-end` to ensure clear-double render instance-initializer is never called.
1 parent 95fff79 commit 37d1f21

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = {
5858
app.options.fingerprint.generateAssetMap = true;
5959
}
6060

61+
app.import('vendor/experimental-render-mode-rehydrate.js');
6162
// get the app registry object and app name so that we can build the fastboot
6263
// tree
6364
this._appRegistry = app.registry;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"ember-cli-lodash-subset": "2.0.1",
3030
"ember-cli-preprocess-registry": "^3.1.0",
3131
"ember-cli-version-checker": "^2.1.0",
32-
"fastboot": "^1.1.3",
32+
"fastboot": "github:rondale-sc/fastboot#utilize-rehydration-serialization-from-glimmer",
3333
"fastboot-express-middleware": "^1.1.0",
3434
"fastboot-transform": "^0.1.2",
3535
"fs-extra": "^4.0.2",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function() {
2+
if (typeof FastBoot === 'undefined') {
3+
var current = document.getElementById('fastboot-body-start');
4+
5+
if (current && current.nextSibling.nodeValue === '%+b:0%') {
6+
Ember.ApplicationInstance.reopen({
7+
_bootSync: function(options) {
8+
if (options === undefined) {
9+
options = {
10+
_renderMode: 'rehydrate'
11+
};
12+
}
13+
14+
return this._super(options);
15+
}
16+
});
17+
18+
// Prevent clearRender by removing `fastboot-body-start` which is already
19+
// guarded for
20+
current.parentNode.removeChild(current);
21+
var end = document.getElementById('fastboot-body-end');
22+
end.parentNode.removeChild(end);
23+
}
24+
}
25+
})();

0 commit comments

Comments
 (0)