Skip to content

Commit

Permalink
Issue #266: fix ReactDOM.render error (#595)
Browse files Browse the repository at this point in the history
* fix: use createRoot()

React 18 uses createRoot() now instead
of ReactDOM.render(). I make the replace-
ment to fix the error.

* perf: use system fonts before load

This fixes the Lighthouse error
"Ensure text remains visible during
webfont load". If the font hasn't
loaded yet, you might get invisible
text. `font-display: swap` fixes
this by using the system font
until the correct one has loaded.
It also improves website load.
  • Loading branch information
PGrad authored and zoobot committed Apr 5, 2023
1 parent 73d602b commit 32f3529
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/components/App/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
font-display: swap;
}

body {
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Footer/Footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
width: 100%;
font-family: "Montserrat", sans-serif;
border-top: rgba(0, 0, 0, 0.472) solid 1px;
font-display: swap;

&__content {
display: flex;
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/Header/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
font-family: wtt-thin;
src: local('wtt-thin'),
url('../../assets/fonts/WTT-THIN.ttf') format('truetype');
font-display: swap;
}

.header {
Expand All @@ -25,6 +26,7 @@
font-size: 1.8rem;
word-spacing: 0.6rem;
border: 1px solid #ddd;
font-display: swap;
}

&__font-link:hover {
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Sidebar/Sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
.sidebar-content {
font-weight: 900;
font-family: "Roboto Mono", monospace;
font-display: swap;
}
5 changes: 3 additions & 2 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
// The webpack.resolve.alias setting in webpack.config.js aliases '@' to 'client/src', so that all
// the import paths can start from there, instead of being relative to the current file.
import App from '@/components/App/App';

ReactDOM.render(<App />, document.querySelector('.root'));
const root = createRoot(document.querySelector('.root'));
root.render(<App />);

0 comments on commit 32f3529

Please sign in to comment.