Skip to content

Commit 7b301f9

Browse files
authored
Proper loading of asynch script setup (#1327)
Async script loading optimizes page load speed. With this fix, a bundle can be loaded "async" and a handler function can determine when to hydrate. For an example of this, see the docs for loadable-components SSR https://loadable-components.com/docs/server-side-rendering/#4-add-loadableready-client-side Loadable-Components is supported by React on Rails Pro: https://www.shakacode.com/react-on-rails-pro
1 parent cc44d70 commit 7b301f9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
1616
Changes since last non-beta release.
1717

1818
*Please add entries here for your pull requests that are not yet released.*
19+
20+
### [12.0.3] - 2020-09-02
21+
#### Fixed
22+
- Async script loading optimizes page load speed. With this fix, a bundle
23+
can be loaded "async" and a handler function can determine when to hydrate.
24+
For an example of this, see the [docs for loadable-components SSR](https://loadable-components.com/docs/server-side-rendering/#4-add-loadableready-client-side).
25+
[PR 1327](https://github.com/shakacode/react_on_rails/pull/1327) by [justin808](https://github.com/justin808).
26+
Loadable-Components is supported by [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
27+
1928
### [12.0.2] - 2020-07-09
2029
#### Fixed
21-
- Remove dependency upon Redux for Typescript types [PR 1323](https://github.com/shakacode/react_on_rails/pull/1306) by [justin808](https://github.com/justin808).
30+
- Remove dependency upon Redux for Typescript types. [PR 1323](https://github.com/shakacode/react_on_rails/pull/1306) by [justin808](https://github.com/justin808).
2231

2332
### [12.0.1] - 2020-07-09
2433
#### Fixed
@@ -934,7 +943,8 @@ Best done with Object destructing:
934943
##### Fixed
935944
- Fix several generator related issues.
936945

937-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.2...master
946+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.3...master
947+
[12.0.3]: https://github.com/shakacode/react_on_rails/compare/12.0.2...12.0.3
938948
[12.0.2]: https://github.com/shakacode/react_on_rails/compare/12.0.1...12.0.2
939949
[12.0.1]: https://github.com/shakacode/react_on_rails/compare/12.0.0...12.0.1
940950
[12.0.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cd react_on_rails/
6262
yarn
6363

6464
# Update the lib directory with babel compiled files
65-
yarn run build:watch
65+
yarn run build-watch
6666
```
6767

6868
You need to do this once:

node_package/src/clientStartup.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,12 @@ export function clientStartup(context: Window | NodeJS.Global): void {
265265

266266
debugTurbolinks('Adding DOMContentLoaded event to install event listeners.');
267267

268-
if (document.readyState === 'complete') {
268+
// So long as the document is not loading, we can assume:
269+
// The document has finished loading and the document has been parsed
270+
// but sub-resources such as images, stylesheets and frames are still loading.
271+
// If lazy asynch loading is used, such as with loadable-components, then the init
272+
// function will install some handler that will properly know when to do hyrdation.
273+
if (document.readyState !== 'loading') {
269274
window.setTimeout(renderInit);
270275
} else {
271276
document.addEventListener('DOMContentLoaded', renderInit);

0 commit comments

Comments
 (0)