-
-
Notifications
You must be signed in to change notification settings - Fork 111
Replace fastboot + prember with a playwright script #1005
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
Open
kategengler
wants to merge
12
commits into
main
Choose a base branch
from
kg-decouple-fastboot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca084bb
Remove old Procfile
kategengler 853b0ff
Add a new service to abstract over fastboot.isFastBoot, in-line
kategengler a94b7e5
Bring ember-data-fastboot into the app
kategengler 507a795
Replace ember-cli-head and correct generation of canonical URL
kategengler ea060f6
Replace fastboot with a prerender script that uses playwright
kategengler b181c98
Don't use npx for http-server
kategengler b6b5828
Group URLs by version and use a separate browser for each version
kategengler dcb8bc5
Use multiple tabs to speed up prerender
kategengler 4123a3a
Install playwright
kategengler d37800b
Fix lint
kategengler c987819
Limit 6.x versions
kategengler 6c492de
Speed up prerender (thanks to @ef4 for spotting the bottleneck)
kategengler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function getHead() { | ||
| return document.head; | ||
| } | ||
|
|
||
| <template> | ||
| {{#in-element (getHead) insertBefore=null}} | ||
| {{yield}} | ||
| {{/in-element}} | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // This removes any pre-rendered elements, so that the booting | ||
| // application will replace the pre-rendered output | ||
| export function clearHtml() { | ||
| let current = document.getElementById('prerender-body-start'); | ||
| let endMarker = document.getElementById('prerender-body-end'); | ||
|
|
||
| if (current && endMarker) { | ||
| let shoeboxNodes = document.querySelectorAll('[type="prerender/shoebox"]'); | ||
| let shoeboxNodesArray = []; // Note that IE11 doesn't support more concise options like Array.from, so we have to do something like this | ||
| for (let i = 0; i < shoeboxNodes.length; i++) { | ||
| shoeboxNodesArray.push(shoeboxNodes[i]); | ||
| } | ||
| let parent = current.parentElement; | ||
| let nextNode; | ||
| do { | ||
| nextNode = current.nextSibling; | ||
| parent.removeChild(current); | ||
| current = nextNode; | ||
| } while ( | ||
| nextNode && | ||
| nextNode !== endMarker && | ||
| shoeboxNodesArray.indexOf(nextNode) < 0 | ||
| ); | ||
| endMarker.parentElement.removeChild(endMarker); | ||
| } | ||
| } | ||
| export default { | ||
| name: 'clear-double-boot', | ||
|
|
||
| initialize(instance) { | ||
| const prerender = instance.lookup('service:prerender'); | ||
| if (!prerender.isPrerendering) { | ||
| const originalDidCreateRootView = instance.didCreateRootView; | ||
|
|
||
| instance.didCreateRootView = function () { | ||
| clearHtml(); | ||
| originalDidCreateRootView.apply(instance, arguments); | ||
| }; | ||
| } | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { dasherize } from '@ember/string'; | ||
|
|
||
| export function initialize(applicationInstance) { | ||
| window.__emberApiDocs = window.__emberApiDocs ?? applicationInstance; | ||
|
|
||
| let store = applicationInstance.lookup('service:store'); | ||
| let shoebox = applicationInstance.lookup('service:shoebox'); | ||
| const isPrerendering = | ||
| applicationInstance.lookup('service:prerender').isPrerendering; | ||
|
|
||
| if (!isPrerendering) { | ||
| if (!shoebox) { | ||
| return; | ||
| } | ||
| let dump = shoebox.retrieve('ember-data-store'); | ||
| if (!dump) { | ||
| return; | ||
| } | ||
| store.pushPayload(dump.records); | ||
| return; | ||
| } | ||
|
|
||
| shoebox?.put('ember-data-store', { | ||
| get records() { | ||
| const modelNames = Object.keys(store._modelFactoryCache); | ||
| return modelNames | ||
| .map((name) => { | ||
| return store.peekAll(name).toArray(); | ||
| }) | ||
| .reduce((a, b) => a.concat(b), []) | ||
| .filter((record) => record.get('isLoaded') && !record.get('isNew')) | ||
| .map((record) => { | ||
| const serializedRecord = record.serialize({ includeId: true }); | ||
|
|
||
| record.eachRelationship((name, meta) => { | ||
| const link = record[meta.kind](name).link(); | ||
|
|
||
| if (link) { | ||
| const dashName = dasherize(name); | ||
|
|
||
| serializedRecord.data.relationships = | ||
| serializedRecord.data.relationships || {}; | ||
| serializedRecord.data.relationships[dashName] = | ||
| serializedRecord.data.relationships[dashName] || {}; | ||
| serializedRecord.data.relationships[dashName].links = { | ||
| related: link, | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
| return serializedRecord; | ||
| }) | ||
| .reduce( | ||
| (a, b) => { | ||
| a.data.push(b.data); | ||
| return a; | ||
| }, | ||
| { data: [] }, | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export default { | ||
| name: 'ember-data-prerender', | ||
| initialize, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import Service from '@ember/service'; | ||
|
|
||
| export default class PrerenderService extends Service { | ||
| get isPrerendering() { | ||
| return window.__isPrerendering; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.