-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for CSS client references
- Loading branch information
Showing
16 changed files
with
342 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::asset::{Asset, AssetVc}; | ||
|
||
/// An [Asset] that should never be placed into a chunk, but whose references | ||
/// should still be followed. | ||
#[turbo_tasks::value_trait] | ||
pub trait PassthroughAsset: Asset {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use anyhow::{bail, Result}; | ||
use turbo_tasks::{primitives::StringVc, Value}; | ||
use turbopack_core::{ | ||
asset::{Asset, AssetContentVc, AssetVc}, | ||
chunk::{PassthroughAsset, PassthroughAssetVc}, | ||
context::{AssetContext, AssetContextVc}, | ||
ident::AssetIdentVc, | ||
reference::AssetReferencesVc, | ||
reference_type::{CssReferenceSubType, ReferenceType}, | ||
}; | ||
|
||
use crate::references::internal::InternalCssAssetReferenceVc; | ||
|
||
#[turbo_tasks::value] | ||
#[derive(Clone)] | ||
pub struct GlobalCssAsset { | ||
source: AssetVc, | ||
inner: AssetVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl GlobalCssAssetVc { | ||
/// Creates a new CSS asset. The CSS is treated as global CSS. | ||
#[turbo_tasks::function] | ||
pub fn new(source: AssetVc, context: AssetContextVc) -> Self { | ||
Self::cell(GlobalCssAsset { | ||
source, | ||
// The underlying CSS is processed through an internal CSS reference. | ||
// This can then be picked up by other rules to treat CSS assets in | ||
// a special way. For instance, in the Next App Router implementation, | ||
// RSC CSS assets will be added to the client references manifest. | ||
inner: context.process( | ||
source, | ||
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)), | ||
), | ||
}) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl Asset for GlobalCssAsset { | ||
#[turbo_tasks::function] | ||
fn ident(&self) -> AssetIdentVc { | ||
self.source.ident().with_modifier(modifier()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn content(&self) -> Result<AssetContentVc> { | ||
bail!("CSS global asset has no contents") | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn references(&self) -> AssetReferencesVc { | ||
AssetReferencesVc::cell(vec![InternalCssAssetReferenceVc::new(self.inner).into()]) | ||
} | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn modifier() -> StringVc { | ||
StringVc::cell("global css".to_string()) | ||
} | ||
|
||
/// A GlobalAsset is a transparent wrapper around an actual CSS asset. | ||
#[turbo_tasks::value_impl] | ||
impl PassthroughAsset for GlobalCssAsset {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.