Skip to content

Commit 0061259

Browse files
authored
Merge pull request #2447 from tf/url-ssr-fix
Fix server-side rendering of scrolled entries
2 parents 89b271d + edc38de commit 0061259

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

entry_types/scrolled/package/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@headlessui/react": "^1.6.6",
1313
"classnames": "^2.3.2",
1414
"core-js": "^3.6.5",
15+
"core-js-pure": "^3.0.0",
1516
"debounce": "^1.2.0",
1617
"deep-assign": "^3.0.0",
1718
"intersection-observer": "^0.7.0",

entry_types/scrolled/package/src/frontend/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import 'core-js/stable';
22
import 'core-js/features/typed-array/uint16-array';
3+
import URLPolyfill from 'core-js-pure/features/url';
34

45
import React from 'react';
56
import ReactRailsUJS from 'react_ujs';
67

78
import {Root, setupI18n} from 'pageflow-scrolled/frontend';
89

10+
// The server-side rendering environment (ExecJS) lacks Web APIs like URL,
11+
// which `core-js/stable` no longer polyfills now that we target modern
12+
// browsers. Install it from core-js-pure (which the browser-targeted
13+
// transforms do not strip) so prerendering can use `new URL(...)`.
14+
if (typeof global.URL === 'undefined') {
15+
global.URL = URLPolyfill;
16+
}
17+
918
ReactRailsUJS.getConstructor = function() {
1019
// Normally this function receives the name of a component, but we
1120
// only need to render one type of component.

0 commit comments

Comments
 (0)