@@ -18,6 +18,7 @@ use turbo_tasks_hash::hash_xxh3_hash64;
18
18
use turbopack:: evaluate_context:: node_evaluate_asset_context;
19
19
use turbopack_core:: {
20
20
asset:: AssetContent ,
21
+ chunk:: ChunkingContext ,
21
22
context:: AssetContext ,
22
23
ident:: AssetIdent ,
23
24
issue:: { IssueExt , IssueSeverity } ,
@@ -218,6 +219,7 @@ impl NextFontGoogleCssModuleReplacer {
218
219
// requests to Google Fonts.
219
220
let env = Vc :: upcast :: < Box < dyn ProcessEnv > > ( CommandLineProcessEnv :: new ( ) ) ;
220
221
let mocked_responses_path = & * env. read ( "NEXT_FONT_GOOGLE_MOCKED_RESPONSES" . into ( ) ) . await ?;
222
+
221
223
let stylesheet_str = mocked_responses_path
222
224
. as_ref ( )
223
225
. map_or_else (
@@ -227,6 +229,7 @@ impl NextFontGoogleCssModuleReplacer {
227
229
. await ?;
228
230
229
231
let font_fallback = get_font_fallback ( * self . project_path , options) ;
232
+ let is_dev_mode = self . execution_context . chunking_context ( ) . is_dev_mode ( ) ;
230
233
231
234
let stylesheet = match stylesheet_str {
232
235
Some ( s) => Some (
@@ -239,13 +242,21 @@ impl NextFontGoogleCssModuleReplacer {
239
242
. owned ( )
240
243
. await ?,
241
244
) ,
242
- None => {
245
+ // Inform the user of the failure to retreive the stylesheet / font, but don't
246
+ // propagate this error. We don't want e.g. offline connections to prevent page
247
+ // renders during development. During production builds, however, this error
248
+ // should propagate.
249
+ None if * is_dev_mode. await ? => {
243
250
println ! (
244
251
"Failed to download `{}` from Google Fonts. Using fallback font instead." ,
245
252
options. await ?. font_family
246
253
) ;
247
254
None
248
255
}
256
+ None => bail ! (
257
+ "Failed to fetch `{}` from Google Fonts." ,
258
+ options. await ?. font_family
259
+ ) ,
249
260
} ;
250
261
251
262
let css_asset = VirtualSource :: new (
@@ -312,13 +323,20 @@ struct NextFontGoogleFontFileOptions {
312
323
#[ turbo_tasks:: value( shared) ]
313
324
pub struct NextFontGoogleFontFileReplacer {
314
325
project_path : ResolvedVc < FileSystemPath > ,
326
+ execution_context : ResolvedVc < ExecutionContext > ,
315
327
}
316
328
317
329
#[ turbo_tasks:: value_impl]
318
330
impl NextFontGoogleFontFileReplacer {
319
331
#[ turbo_tasks:: function]
320
- pub fn new ( project_path : ResolvedVc < FileSystemPath > ) -> Vc < Self > {
321
- Self :: cell ( NextFontGoogleFontFileReplacer { project_path } )
332
+ pub fn new (
333
+ project_path : ResolvedVc < FileSystemPath > ,
334
+ execution_context : ResolvedVc < ExecutionContext > ,
335
+ ) -> Vc < Self > {
336
+ Self :: cell ( NextFontGoogleFontFileReplacer {
337
+ project_path,
338
+ execution_context,
339
+ } )
322
340
}
323
341
}
324
342
@@ -616,16 +634,9 @@ async fn fetch_from_google_fonts(
616
634
)
617
635
. await ?;
618
636
619
- Ok ( match & * result {
637
+ Ok ( match * result {
620
638
Ok ( r) => Some ( * r. await ?. body ) ,
621
639
Err ( err) => {
622
- // Inform the user of the failure to retreive the stylesheet / font, but don't
623
- // propagate this error. We don't want e.g. offline connections to prevent page
624
- // renders during development. During production builds, however, this error
625
- // should propagate.
626
- //
627
- // TODO(WEB-283): Use fallback in dev in this case
628
- // TODO(WEB-293): Fail production builds (not dev) in this case
629
640
err. to_issue ( IssueSeverity :: Warning . into ( ) , virtual_path)
630
641
. to_resolved ( )
631
642
. await ?
0 commit comments