File tree Expand file tree Collapse file tree 11 files changed +72
-22
lines changed
ol-components/src/components Expand file tree Collapse file tree 11 files changed +72
-22
lines changed Original file line number Diff line number Diff line change 3
3
"version" : " 0.1.0" ,
4
4
"private" : true ,
5
5
"scripts" : {
6
- "dev" : " PORT=${PORT:-8062} next dev" ,
6
+ "dev" : " PORT=${PORT:-8062} TZ=UTC next dev" ,
7
7
"build" : " next build" ,
8
8
"build:no-lint" : " next build --no-lint" ,
9
- "start" : " next start" ,
9
+ "start" : " TZ=UTC next start" ,
10
10
"lint" : " next lint"
11
11
},
12
12
"dependencies" : {
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {
13
13
NewsEventsListFeedTypeEnum ,
14
14
} from "api/hooks/newsEvents"
15
15
import type { NewsFeedItem , EventFeedItem } from "api/v0"
16
- import { formatDate } from "ol-utilities"
16
+ import { LocalDate } from "ol-utilities"
17
17
import { RiArrowRightSLine } from "@remixicon/react"
18
18
import Link from "next/link"
19
19
@@ -196,7 +196,7 @@ const Story: React.FC<{ item: NewsFeedItem; mobile: boolean }> = ({
196
196
{ item . title }
197
197
</ Card . Title >
198
198
< Card . Footer >
199
- Published: { formatDate ( item . news_details ?. publish_date ) }
199
+ Published: < LocalDate date = { item . news_details ?. publish_date } />
200
200
</ Card . Footer >
201
201
</ StoryCard >
202
202
)
@@ -226,16 +226,16 @@ const NewsEventsSection: React.FC = () => {
226
226
< Card . Content >
227
227
< EventDate >
228
228
< EventDay >
229
- { formatDate (
230
- ( item as EventFeedItem ) . event_details ?. event_datetime ,
231
- "D" ,
232
- ) }
229
+ < LocalDate
230
+ date = { ( item as EventFeedItem ) . event_details ?. event_datetime }
231
+ format = "D"
232
+ />
233
233
</ EventDay >
234
234
< EventMonth >
235
- { formatDate (
236
- ( item as EventFeedItem ) . event_details ?. event_datetime ,
237
- "MMM" ,
238
- ) }
235
+ < LocalDate
236
+ date = { ( item as EventFeedItem ) . event_details ?. event_datetime }
237
+ format = "MMM"
238
+ />
239
239
</ EventMonth >
240
240
</ EventDate >
241
241
< Link href = { item . url } data-card-link >
Original file line number Diff line number Diff line change 9
9
} from "@remixicon/react"
10
10
import { LearningResource } from "api"
11
11
import {
12
- formatDate ,
12
+ LocalDate ,
13
13
getReadableResourceType ,
14
14
DEFAULT_RESOURCE_IMG ,
15
15
getLearningResourcePrices ,
@@ -149,7 +149,8 @@ const StartDate: React.FC<{ resource: LearningResource; size?: Size }> = ({
149
149
const format = size === "small" ? "MMM DD, YYYY" : "MMMM DD, YYYY"
150
150
const formatted = anytime
151
151
? "Anytime"
152
- : startDate && formatDate ( startDate , format )
152
+ : startDate && < LocalDate date = { startDate } format = { format } />
153
+
153
154
if ( ! formatted ) return null
154
155
155
156
const showLabel = size !== "small" || anytime
Original file line number Diff line number Diff line change 9
9
} from "@remixicon/react"
10
10
import { ResourceTypeEnum , LearningResource } from "api"
11
11
import {
12
- formatDate ,
12
+ LocalDate ,
13
13
getReadableResourceType ,
14
14
DEFAULT_RESOURCE_IMG ,
15
15
pluralize ,
@@ -151,7 +151,7 @@ export const StartDate: React.FC<{ resource: LearningResource }> = ({
151
151
const startDate = getResourceDate ( resource )
152
152
const formatted = anytime
153
153
? "Anytime"
154
- : startDate && formatDate ( startDate , "MMMM DD, YYYY" )
154
+ : startDate && < LocalDate date = { startDate } format = "MMMM DD, YYYY" />
155
155
if ( ! formatted ) return null
156
156
157
157
return (
Original file line number Diff line number Diff line change 8
8
getDisplayPrice ,
9
9
getRunPrices ,
10
10
showStartAnytime ,
11
+ NoSSR ,
11
12
} from "ol-utilities"
12
13
13
14
const DifferingRuns = styled . div ( {
@@ -103,7 +104,9 @@ const DifferingRunsTable: React.FC<{ resource: LearningResource }> = ({
103
104
</ DifferingRunHeader >
104
105
{ resource . runs ?. map ( ( run , index ) => (
105
106
< DifferingRun key = { index } >
106
- < DateData > { formatRunDate ( run , asTaughtIn ) } </ DateData >
107
+ < DateData >
108
+ < NoSSR > { formatRunDate ( run , asTaughtIn ) } </ NoSSR >
109
+ </ DateData >
107
110
{ run . resource_prices && (
108
111
< PriceData >
109
112
< span > { getDisplayPrice ( getRunPrices ( run ) [ "course" ] ) } </ span >
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
24
24
formatRunDate ,
25
25
getLearningResourcePrices ,
26
26
showStartAnytime ,
27
+ NoSSR ,
27
28
} from "ol-utilities"
28
29
import { theme } from "../ThemeProvider/ThemeProvider"
29
30
import DifferingRunsTable from "./DifferingRunsTable"
@@ -255,7 +256,11 @@ const INFO_ITEMS: InfoItemConfig = [
255
256
const totalDatesWithRuns =
256
257
resource . runs ?. filter ( ( run ) => run . start_date !== null ) . length || 0
257
258
if ( allRunsAreIdentical ( resource ) && totalDatesWithRuns > 0 ) {
258
- return < RunDates resource = { resource } />
259
+ return (
260
+ < NoSSR >
261
+ < RunDates resource = { resource } />
262
+ </ NoSSR >
263
+ )
259
264
} else return null
260
265
} ,
261
266
} ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { ButtonLink } from "../Button/Button"
7
7
import type { LearningResource , LearningResourceRun } from "api"
8
8
import { ResourceTypeEnum , PlatformEnum } from "api"
9
9
import {
10
+ NoSSR ,
10
11
formatDate ,
11
12
capitalize ,
12
13
DEFAULT_RESOURCE_IMG ,
@@ -299,7 +300,7 @@ const ResourceDescription = ({ resource }: { resource?: LearningResource }) => {
299
300
return (
300
301
< Description
301
302
/**
302
- * Resource descriptions can contain HTML. They are santiized on the
303
+ * Resource descriptions can contain HTML. They are sanitized on the
303
304
* backend during ETL. This is safe to render.
304
305
*/
305
306
dangerouslySetInnerHTML = { { __html : resource . description || "" } }
@@ -384,7 +385,7 @@ const LearningResourceExpandedV1: React.FC<LearningResourceExpandedV1Props> = ({
384
385
. map ( ( run ) => {
385
386
return {
386
387
value : run . id . toString ( ) ,
387
- label : formatRunDate ( run , asTaughtIn ) ,
388
+ label : < NoSSR > { formatRunDate ( run , asTaughtIn ) } </ NoSSR > ,
388
389
}
389
390
} ) ?? [ ]
390
391
@@ -415,7 +416,7 @@ const LearningResourceExpandedV1: React.FC<LearningResourceExpandedV1Props> = ({
415
416
return (
416
417
< DateSingle >
417
418
< DateLabel > { label } </ DateLabel >
418
- { formatted ?? "" }
419
+ < NoSSR > { formatted ?? "" } </ NoSSR >
419
420
</ DateSingle >
420
421
)
421
422
}
Original file line number Diff line number Diff line change
1
+ import React from "react"
2
+ import { NoSSR } from "../ssr/NoSSR"
3
+ import { formatDate } from "./format"
4
+
5
+ type LocalDateProps = {
6
+ date ?: string | Date | null
7
+ /**
8
+ * A Moment.js format string. See https://momentjs.com/docs/#/displaying/format/
9
+ */
10
+ format ?: string
11
+ }
12
+
13
+ /* Component to render dates only on the client as these are displayed
14
+ * according to the user's locale (generally, not all Moment.js format tokens
15
+ * are localized) causing an error due to hydration mismatch.
16
+ */
17
+ export const LocalDate = ( { date, format = "MMM D, YYYY" } : LocalDateProps ) => {
18
+ if ( ! date ) return null
19
+ return < NoSSR > { formatDate ( date , format ) } </ NoSSR >
20
+ }
Original file line number Diff line number Diff line change 1
1
import moment from "moment"
2
2
3
+ /* Instances must be wrapped in <NoSSR> to avoid SSR hydration mismatches.
4
+ */
3
5
export const formatDate = (
4
6
/**
5
7
* Date string or date.
6
8
*/
7
9
date : string | Date ,
8
10
/**
9
- * A momentjs format string. See https://momentjs.com/docs/#/displaying/format/
11
+ * A Moment.js format string. See https://momentjs.com/docs/#/displaying/format/
10
12
*/
11
13
format = "MMM D, YYYY" ,
12
14
) => {
Original file line number Diff line number Diff line change 6
6
export * from "./styles"
7
7
8
8
export * from "./date/format"
9
+ export * from "./date/LocalDate"
9
10
export * from "./learning-resources/learning-resources"
10
11
export * from "./learning-resources/pricing"
11
12
export * from "./strings/html"
@@ -14,3 +15,4 @@ export * from "./hooks"
14
15
export * from "./querystrings"
15
16
export * from "./lib"
16
17
export * from "./images/backgroundImages"
18
+ export * from "./ssr/NoSSR"
You can’t perform that action at this time.
0 commit comments