Skip to content
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

Use Puppeteer for BTR and support statically generating route index files #91

Merged
merged 18 commits into from
Nov 27, 2018

Conversation

agubler
Copy link
Member

@agubler agubler commented Nov 9, 2018

Type: feature

The following has been addressed in the PR:

Description:

Swaps JSDOM for puppeteer to run BTR and add additional support to statically render index files for paths when using the history API (StateHistory) routing in the application.

Resolves #87
Resolves #92

@codecov
Copy link

codecov bot commented Nov 9, 2018

Codecov Report

Merging #91 into master will increase coverage by 0.18%.
The diff coverage is 96.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
+ Coverage   84.54%   84.72%   +0.18%     
==========================================
  Files          33       33              
  Lines        1171     1211      +40     
  Branches      321      332      +11     
==========================================
+ Hits          990     1026      +36     
- Misses        181      185       +4
Impacted Files Coverage Δ
src/build-time-render/hasBuildTimeRender.ts 71.42% <60%> (-28.58%) ⬇️
src/build-time-render/BuildTimeRender.ts 98.4% <98.31%> (-1.6%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a87b88...0d84af4. Read the comment docs.

@@ -1,7 +1,7 @@
{
"extends": "./node_modules/@dojo/scripts/intern/base.json",
"coverage": [
"./dist/dev/src/**/*.js"
"./dist/dev/src/**/*.js", "!./dist/dev/src/build-time-render/helpers.js"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluding the helpers because cannot instrument code that get's executed in puppeteers browser context.

@agubler agubler added enhancement next Issue/Pull Request for the next major version labels Nov 9, 2018
},
{} as any
);
this._useHistory = useHistory !== undefined ? useHistory : paths.length > 0 && !/^#.*/.test(initialPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While auto-detecting the use history based on the existence of a # (or lack there of) makes this a smarter module, it would need to be well documented to avoid unexpected behavior. If someone intends to use #, but just forgets to put it at the start of their path, it will pick it up and run as if they meant to use history.

I personally am a fan of having a default (hash), and making any change to that strategy being a deliberate change by the developer in the config file to avoid confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to introduce another option to the .dojorc, we are thinking about supporting routing type via a has flag (feature flag) so this is really to support both before we implement that in cli-build-app. It might change between now and version 5.0.0 but that's fine in the alpha/betas and sniffing the route enables use to use this immediately.

You're right though, if we decide to keep the detection base on # it would have to be documented well. At the moment, without the # build time rendering wouldn't work for hash history (just like routing in the browser).

return css;
}, '');

html = html.replace(/^(\s*)(\r\n?|\n)/gm, '').trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following would better minify the html

html = html.replace(/(^\s*|\r\n|\n|\t|\s$)/gm, '').trim();

JS Fiddle: https://jsfiddle.net/vqn3a6g5/19

Also should this occur after the script and css variables are added in? Since you don't currently the following occurs: https://gist.github.com/KaneFreeman/7cb2991eaa04e516e23e7eb1d720b04d

setHasFlags
} from './helpers';
const filterCss = require('filter-css');
const puppeteer = require('puppeteer');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a @types/puppeteer. Letting this be:

import { launch } from 'puppeteer';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KaneFreeman The types requires me to bump the TS version which I didn't want to do (as it uses conditional types), so I decided against using the types until we purposely bump the TS version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agubler Gotta. Sounds good.


export function generateBasePath(route = '__app_root__') {
return `<script>
window.__public_path__ = window.location.href.replace('${route}/', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is causing the url to be rewritten.

Loading up an App with a default /home route locally (on localhost:9999) causes the browser to redirect to http://localhost:9999/http://localhost:9999/home.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KaneFreeman updated

@agubler agubler dismissed KaneFreeman’s stale review November 27, 2018 08:11

comment addressed

@agubler agubler merged commit 4f21fb4 into dojo:master Nov 27, 2018
@agubler agubler mentioned this pull request Nov 28, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement next Issue/Pull Request for the next major version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants