-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dev): lazily generate CSS bundle (#6535)
- Loading branch information
1 parent
72d7377
commit a1855e4
Showing
16 changed files
with
187 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@remix-run/css-bundle": patch | ||
"@remix-run/dev": patch | ||
--- | ||
|
||
Lazily generate CSS bundle when import of `@remix-run/css-bundle` is detected |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
declare const __INJECT_CSS_BUNDLE_HREF__: string | undefined; | ||
|
||
// Injected by `cssBundlePlugin` | ||
let cssBundleHref: string | undefined = | ||
typeof __INJECT_CSS_BUNDLE_HREF__ === "string" | ||
? __INJECT_CSS_BUNDLE_HREF__ | ||
: undefined; | ||
|
||
export { cssBundleHref }; |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,45 @@ | ||
import * as Channel from "../channel"; | ||
|
||
export type LazyValue<T> = { | ||
get: () => Promise<T>; | ||
cancel: () => void; | ||
}; | ||
|
||
export const createLazyValue = <T>(args: { | ||
get: () => Promise<T>; | ||
onCancel?: (args: { | ||
resolve: (value: T) => void; | ||
reject: (err?: any) => void; | ||
}) => void; | ||
}): LazyValue<T> => { | ||
let channel: Channel.Type<T> | undefined; | ||
|
||
return { | ||
async get() { | ||
// Create channel and request lazy value on first `get` call | ||
if (!channel) { | ||
channel = Channel.create(); | ||
try { | ||
channel.ok(await args.get()); | ||
} catch (err) { | ||
channel.err(err); | ||
} | ||
} | ||
|
||
// Share the same result with all callers | ||
let result = await channel.result; | ||
|
||
if (!result.ok) { | ||
throw result.error; | ||
} | ||
|
||
return result.value; | ||
}, | ||
cancel() { | ||
args.onCancel?.({ | ||
resolve: (value) => channel?.ok(value), | ||
reject: (error) => channel?.err(error), | ||
}); | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.