summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2024-02-22 11:11:41 -0500
committerGravatar GitHub <noreply@github.com> 2024-02-22 11:11:41 -0500
commit3cc20109277813ccb9578ca87a8b0d680a73c35c (patch)
treeb063e3bd16eb367f2ae13c712f2f906204e33885
parentc856c729404196900a7386c8426b81e79684a6a9 (diff)
downloadastro-3cc20109277813ccb9578ca87a8b0d680a73c35c.tar.gz
astro-3cc20109277813ccb9578ca87a8b0d680a73c35c.tar.zst
astro-3cc20109277813ccb9578ca87a8b0d680a73c35c.zip
Fix cssesc from breaking browser code (#10194)
* Fix cssesc from breaking browser code * Include specific thing instead * Update .changeset/quick-bottles-march.md Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * Fix ISR * Remove query stripping altogether * Warn on client usage * Fix build * oops --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
-rw-r--r--.changeset/cuddly-ads-fail.md5
-rw-r--r--.changeset/quick-bottles-march.md5
-rw-r--r--packages/astro/src/content/vite-plugin-content-virtual-mod.ts13
-rw-r--r--packages/astro/src/core/build/plugins/plugin-content.ts1
-rw-r--r--packages/astro/src/transitions/vite-plugin-transitions.ts7
-rw-r--r--packages/integrations/vercel/src/serverless/adapter.ts14
6 files changed, 27 insertions, 18 deletions
diff --git a/.changeset/cuddly-ads-fail.md b/.changeset/cuddly-ads-fail.md
new file mode 100644
index 000000000..77d18cc51
--- /dev/null
+++ b/.changeset/cuddly-ads-fail.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/vercel": patch
+---
+
+Fix loading client-scripts in dev with ISR
diff --git a/.changeset/quick-bottles-march.md b/.changeset/quick-bottles-march.md
new file mode 100644
index 000000000..d8dd924e9
--- /dev/null
+++ b/.changeset/quick-bottles-march.md
@@ -0,0 +1,5 @@
+---
+"astro": patch
+---
+
+Fixes an issue related to content collections usage in browser context caused by `csssec`
diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
index 878e41e35..52f2d65f0 100644
--- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
+++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
@@ -61,13 +61,14 @@ export function astroContentVirtualModPlugin({
}
}
},
- async load(id) {
+ async load(id, args) {
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
const lookupMap = await generateLookupMap({
settings,
fs,
});
- const code = await generateContentEntryFile({ settings, fs, lookupMap, IS_DEV, IS_SERVER });
+ const isClient = !args?.ssr;
+ const code = await generateContentEntryFile({ settings, fs, lookupMap, IS_DEV, IS_SERVER, isClient });
return {
code,
@@ -102,12 +103,14 @@ export async function generateContentEntryFile({
lookupMap,
IS_DEV,
IS_SERVER,
+ isClient
}: {
settings: AstroSettings;
fs: typeof nodeFs;
lookupMap: ContentLookupMap;
IS_DEV: boolean;
IS_SERVER: boolean;
+ isClient: boolean;
}) {
const contentPaths = getContentPaths(settings.config);
const relContentDir = rootRelativePath(settings.config.root, contentPaths.contentDir);
@@ -143,13 +146,15 @@ export async function generateContentEntryFile({
renderEntryGlobResult = getStringifiedCollectionFromLookup('render', relContentDir, lookupMap);
}
- const virtualModContents = nodeFs
+ let virtualModContents = nodeFs
.readFileSync(contentPaths.virtualModTemplate, 'utf-8')
.replace('@@CONTENT_DIR@@', relContentDir)
.replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult)
.replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult)
.replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult)
- .replace('/* @@LOOKUP_MAP_ASSIGNMENT@@ */', `lookupMap = ${JSON.stringify(lookupMap)};`);
+ .replace('/* @@LOOKUP_MAP_ASSIGNMENT@@ */', `lookupMap = ${JSON.stringify(lookupMap)};`) +
+ (isClient ? `
+console.warn('astro:content is only supported running server-side. Using it in the browser will lead to bloated bundles and slow down page load. In the future it will not be supported.');` : '');
return virtualModContents;
}
diff --git a/packages/astro/src/core/build/plugins/plugin-content.ts b/packages/astro/src/core/build/plugins/plugin-content.ts
index c28fa6904..a3a8a376a 100644
--- a/packages/astro/src/core/build/plugins/plugin-content.ts
+++ b/packages/astro/src/core/build/plugins/plugin-content.ts
@@ -164,6 +164,7 @@ function vitePluginContent(
lookupMap,
IS_DEV: false,
IS_SERVER: false,
+ isClient: false,
});
this.emitFile({
type: 'prebuilt-chunk',
diff --git a/packages/astro/src/transitions/vite-plugin-transitions.ts b/packages/astro/src/transitions/vite-plugin-transitions.ts
index 16cb174ba..d88c96f89 100644
--- a/packages/astro/src/transitions/vite-plugin-transitions.ts
+++ b/packages/astro/src/transitions/vite-plugin-transitions.ts
@@ -10,6 +10,13 @@ const resolvedVirtualClientModuleId = '\0' + virtualClientModuleId;
export default function astroTransitions({ settings }: { settings: AstroSettings }): vite.Plugin {
return {
name: 'astro:transitions',
+ config() {
+ return {
+ optimizeDeps: {
+ include: ['astro > cssesc'],
+ },
+ };
+ },
async resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts
index 68897c6dc..db8f0c494 100644
--- a/packages/integrations/vercel/src/serverless/adapter.ts
+++ b/packages/integrations/vercel/src/serverless/adapter.ts
@@ -287,20 +287,6 @@ export default function vercelServerless({
);
}
},
- 'astro:server:setup'({ server }) {
- // isr functions do not have access to search params, this middleware removes them for the dev mode
- if (isr) {
- const exclude_ = typeof isr === 'object' ? isr.exclude ?? [] : [];
- // we create a regex to emulate vercel's production behavior
- const exclude = exclude_.concat('/_image').map((ex) => new RegExp(escapeRegex(ex)));
- server.middlewares.use(function removeIsrParams(req, _, next) {
- const { pathname } = new URL(`https://example.com${req.url}`);
- if (exclude.some((ex) => ex.test(pathname))) return next();
- req.url = pathname;
- return next();
- });
- }
- },
'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => {
_entryPoints = entryPoints;
_middlewareEntryPoint = middlewareEntryPoint;