Skip to content

Commit ea060f6

Browse files
committed
Replace fastboot with a prerender script that uses playwright
- Replace ember-cli-head with <InHead> component - Replace fastboot's shoebox behavior with similar
1 parent 507a795 commit ea060f6

24 files changed

Lines changed: 307 additions & 552 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ local.log
2929
# ember-api-docs-data checkout
3030
/ember-api-docs-data/
3131
/ember-api-docs-data
32+
33+
# prerendered output tmp dir
34+
/prerender

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ cd to the cloned ember-api-docs directory
8080
ensure Node.js and npm are installed
8181

8282
follow these commands to build ember.js
83-
- npm install
84-
- npm build
83+
- pnpm install
84+
- pnpm build
8585
```
8686

8787
## Development steps
8888

8989
1. Follow the setup steps listed above under [Building Ember.js API](#building-emberjs-api-docs).
9090

91-
2. To start the development server, run `npm start`.
91+
2. To start the development server, run `pnpm start`.
9292

93-
3. To run all tests run `npm test`
93+
3. To run all tests run `pnpm test`
9494

95-
4. To run the app with fastboot cli like our server deployment run the following commands,
95+
4. To run prerender and run the site as it would be for a production deploy,
9696
```
97-
- ember deploy production
98-
- ./bin/ember-fastboot tmp/deploy-dist
97+
- pnpm build
98+
- cd dist && npx http-server
9999
```
100100

101101

app/adapters/application.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ export default class Application extends JSONAPIAdapter {
8080
throw new Error('Unexpected model lookup');
8181
}
8282

83-
const base = this.fastboot.isFastBoot
84-
? config.APP.domain
85-
: window.location.origin;
83+
const base = window.location.origin;
8684

8785
url = `${base}/${url}.json`;
8886
try {

app/instance-initializers/clear-double-boot.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
// Overriding the ember-cli-fastboot instance-initializer so that
2-
// we can own this and migrate away.
3-
// When using `ember serve` when fastboot addon is installed the application
4-
// output will already be rendered to the DOM when the actual JavaScript
5-
// loads. Ember does not automatically clear its `rootElement` so this
6-
// leads to the "double" applications being visible at once (only the
7-
// "bottom" one is running via JS and is interactive).
8-
//
9-
// This removes any pre-rendered ember-view elements, so that the booting
1+
// This removes any pre-rendered elements, so that the booting
102
// application will replace the pre-rendered output
113
export function clearHtml() {
12-
let current = document.getElementById('fastboot-body-start');
13-
let endMarker = document.getElementById('fastboot-body-end');
4+
let current = document.getElementById('prerender-body-start');
5+
let endMarker = document.getElementById('prerender-body-end');
146

157
if (current && endMarker) {
16-
let shoeboxNodes = document.querySelectorAll('[type="fastboot/shoebox"]');
8+
let shoeboxNodes = document.querySelectorAll('[type="prerender/shoebox"]');
179
let shoeboxNodesArray = []; // Note that IE11 doesn't support more concise options like Array.from, so we have to do something like this
1810
for (let i = 0; i < shoeboxNodes.length; i++) {
1911
shoeboxNodesArray.push(shoeboxNodes[i]);
@@ -38,7 +30,7 @@ export default {
3830
initialize(instance) {
3931
const prerender = instance.lookup('service:prerender');
4032
if (!prerender.isPrerendering) {
41-
var originalDidCreateRootView = instance.didCreateRootView;
33+
const originalDidCreateRootView = instance.didCreateRootView;
4234

4335
instance.didCreateRootView = function () {
4436
clearHtml();

app/instance-initializers/ember-data-fastboot.js renamed to app/instance-initializers/ember-data-prerender.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import Ember from 'ember';
1+
import { dasherize } from '@ember/string';
22

33
export function initialize(applicationInstance) {
4+
window.__emberApiDocs = window.__emberApiDocs ?? applicationInstance;
5+
46
let store = applicationInstance.lookup('service:store');
5-
let shoebox = applicationInstance.lookup('service:fastboot').get('shoebox');
7+
let shoebox = applicationInstance.lookup('service:shoebox');
68
const isPrerendering =
79
applicationInstance.lookup('service:prerender').isPrerendering;
810

@@ -18,7 +20,7 @@ export function initialize(applicationInstance) {
1820
return;
1921
}
2022

21-
shoebox.put('ember-data-store', {
23+
shoebox?.put('ember-data-store', {
2224
get records() {
2325
const modelNames = Object.keys(store._modelFactoryCache);
2426
return modelNames
@@ -34,7 +36,7 @@ export function initialize(applicationInstance) {
3436
const link = record[meta.kind](name).link();
3537

3638
if (link) {
37-
const dashName = Ember.String.dasherize(name);
39+
const dashName = dasherize(name);
3840

3941
serializedRecord.data.relationships =
4042
serializedRecord.data.relationships || {};
@@ -60,6 +62,6 @@ export function initialize(applicationInstance) {
6062
}
6163

6264
export default {
63-
name: 'ember-data-fastboot',
65+
name: 'ember-data-prerender',
6466
initialize,
6567
};

app/instance-initializers/ember-meta-store.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { isPresent } from '@ember/utils';
22

33
export function initialize(appInstance) {
44
const metaStore = appInstance.lookup('service:meta-store');
5-
const fastBootService = appInstance.lookup('service:fastboot');
5+
const shoebox = appInstance.lookup('service:shoebox');
6+
const isPrerendering = appInstance.lookup('service:prerender').isPrerendering;
67

7-
const shoebox = fastBootService.get('shoebox');
8-
9-
if (typeof FastBoot !== 'undefined') {
8+
if (isPrerendering) {
109
shoebox.put(
1110
'meta-store',
1211
metaStore.getProperties('availableProjectVersions', 'projectRevMap'),

app/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import EmberRouter from '@ember/routing/router';
22
import config from 'ember-api-docs/config/environment';
33
import { withHashSupport } from 'ember-api-docs/utils/url-hash-polyfill';
44

5-
// The following adds support for URL hash routing for those URLs not rendered with fastboot
5+
// The following adds support for URL hash routing for those URLs not prerendered
66
@withHashSupport
77
class AppRouter extends EmberRouter {
88
location = config.locationType;

app/routes/application.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ export default class ApplicationRoute extends Route {
2323
@service
2424
routerScroll;
2525

26+
@service
27+
shoebox;
28+
2629
constructor() {
2730
super(...arguments);
2831
if (!this.prerender.isPrerendering) {
2932
this.router.on('routeDidChange', this.trackPage);
3033

3134
/* Hax from https://github.com/DockYard/ember-router-scroll/issues/263
3235
to handle router scroll behavior when the page was initially served
33-
with fastboot
36+
pre-rendered
3437
*/
3538
this.routerScroll.set('preserveScrollPosition', true);
3639

@@ -40,8 +43,16 @@ export default class ApplicationRoute extends Route {
4043
}
4144
}, 1000);
4245
}
46+
47+
if (this.prerender.isPrerendering) {
48+
this.router.on('routeDidChange', this.storeShoebox);
49+
}
4350
}
4451

52+
storeShoebox = () => {
53+
this.shoebox.store();
54+
};
55+
4556
trackPage = () => {
4657
// this is constant for this app and is only used to identify page views in the GA dashboard
4758
const hostname = ENV.APP.domain.replace(/(http|https)?:?\/\//g, '');

app/routes/not-found.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import Route from '@ember/routing/route';
2-
import { service } from '@ember/service';
32

43
export default class NotFoundRoute extends Route {
5-
@service fastboot;
6-
7-
beforeModel() {
8-
if (!this.fastboot.isFastBoot) {
9-
return;
10-
}
11-
12-
this.fastboot.response.statusCode = 404;
13-
}
14-
154
redirect() {
165
if (typeof window === 'undefined' || !window.location) {
176
return;

app/routes/project-version.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import semverCompare from 'semver-compare';
44
import getFullVersion from 'ember-api-docs/utils/get-full-version';
55
import getLastVersion from 'ember-api-docs/utils/get-last-version';
66

7-
import config from 'ember-api-docs/config/environment';
8-
97
export default class ProjectVersionRoute extends Route {
10-
@service
11-
fastboot;
12-
138
@service
149
headData;
1510

@@ -115,16 +110,6 @@ export default class ProjectVersionRoute extends Route {
115110
_gatherHeadDataFromVersion(model, projectVersion) {
116111
this.headData.isRelease = projectVersion === 'release';
117112
this.headData.compactVersion = model.get('compactVersion');
118-
this.headData.urlVersion = projectVersion;
119-
if (!this.headData.isRelease) {
120-
let request = this.fastboot.request;
121-
let href = this.fastboot.isFastBoot
122-
? `${config.APP.domain}/${request.path}`
123-
: window.location.href;
124-
let version = new RegExp(model.get('compactVersion'), 'g');
125-
let canonicalUrl = href.replace(version, 'release');
126-
this.headData.canonicalUrl = canonicalUrl;
127-
}
128113
}
129114

130115
serialize(model) {

0 commit comments

Comments
 (0)