Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #1804, make bundle scripts and raven activation async
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Nov 16, 2016
1 parent 6c34ecf commit e4ac283
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion server/src/pages/creating/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Head extends React.Component {
render() {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={this.props.staticLink("/static/js/creating-bundle.js")}></script>
<script src={this.props.staticLink("/static/js/creating-bundle.js")} async></script>
<link rel="stylesheet" href={this.props.staticLink("/static/css/simple.css")} />
</reactruntime.HeadTemplate>
);
Expand Down
2 changes: 1 addition & 1 deletion server/src/pages/homepage/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Head extends React.Component {
render() {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={this.props.staticLink("/static/js/homepage-bundle.js")}></script>
<script src={this.props.staticLink("/static/js/homepage-bundle.js")} async></script>
<link rel="stylesheet" href={this.props.staticLink("/static/css/styles.css")} />
<meta name="viewport" content="width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta name="description" content="Share anything on the web with anyone using Page Shot." />
Expand Down
2 changes: 1 addition & 1 deletion server/src/pages/leave-page-shot/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Head extends React.Component {
render() {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={this.props.staticLink("/static/js/leave-bundle.js")}></script>
<script src={this.props.staticLink("/static/js/leave-bundle.js")} async></script>
<link rel="stylesheet" href={ this.props.staticLink("/static/css/warning-page.css") } />
</reactruntime.HeadTemplate>
);
Expand Down
2 changes: 1 addition & 1 deletion server/src/pages/metrics/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Head extends React.Component {
render() {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={this.props.staticLink("/static/js/metrics-bundle.js")}></script>
<script src={this.props.staticLink("/static/js/metrics-bundle.js")} async></script>
<link rel="stylesheet" href={this.props.staticLink("/static/css/metrics.css")} />
</reactruntime.HeadTemplate>
);
Expand Down
4 changes: 2 additions & 2 deletions server/src/pages/shot/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class Head extends React.Component {
if (expired) {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={ this.props.staticLink("/static/js/shot-bundle.js") } />
<script src={ this.props.staticLink("/static/js/shot-bundle.js") } async />
<link rel="stylesheet" href={ this.props.staticLink("/static/css/frame.css") } />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</reactruntime.HeadTemplate>
);
} else {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={ this.props.staticLink("/static/js/shot-bundle.js") } />
<script src={ this.props.staticLink("/static/js/shot-bundle.js") } async />
<link rel="stylesheet" href={ this.props.staticLink("/static/css/frame.css") } />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="alternate" type="application/json+oembed" href={this.props.shot.oembedUrl} title={`${this.props.shot.title} oEmbed`} />
Expand Down
2 changes: 1 addition & 1 deletion server/src/pages/shotindex/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Head extends React.Component {
render() {
return (
<reactruntime.HeadTemplate {...this.props}>
<script src={this.props.staticLink("/static/js/shotindex-bundle.js")}></script>
<script src={this.props.staticLink("/static/js/shotindex-bundle.js")} async></script>
<link rel="stylesheet" href={this.props.staticLink("/static/css/shot-index.css")} />
</reactruntime.HeadTemplate>
);
Expand Down
10 changes: 9 additions & 1 deletion server/src/reactrender.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ exports.render = function (req, res, page) {
`.trim();
if (! page.noBrowserJavascript) {
// FIXME: we should just inline the addReactScripts functionality in this function:
doc = addReactScripts(doc, `controller.launch(${JSON.stringify(jsonModel)});`, req.cspNonce);
let script = `\
window.initialModel = ${JSON.stringify(jsonModel)};
window.initialModelLaunched = false;
if (window.controller) {
window.controller.launch(window.initialModel);
window.initialModelLaunched = true;
}
`;
doc = addReactScripts(doc, script, req.cspNonce);
}
res.send(doc);
}).catch((err) => {
Expand Down
11 changes: 10 additions & 1 deletion server/src/reactruntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.HeadTemplate = class HeadTemplate extends React.Component {
<link rel="shortcut icon" href={this.props.staticLink("/static/img/pageshot-icon-32.png")} />
{ analyticsScript }
{ activationScript }
{ this.props.sentryPublicDSN ? <script src={this.props.staticLink("/install-raven.js")} /> : null }
{ this.props.sentryPublicDSN ? <script src={this.props.staticLink("/install-raven.js")} async /> : null }
{this.props.children}
</head>
);
Expand Down Expand Up @@ -108,3 +108,12 @@ exports.Page = class Page {
exports.Page.prototype.ATTRS = `
dir viewModule noBrowserJavascript
`.split(/\s+/g);

if (typeof window !== "undefined") {
setTimeout(() => {
if (window.initialModel !== undefined && ! window.initialModelLaunched) {
window.initialModelLaunched = true;
window.controller.launch(window.initialModel);
}
});
}

0 comments on commit e4ac283

Please sign in to comment.