Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(docsite): validate Vercel sandbox fix (#6859)

nynexman446433eb65c56865
diff --git a/apps/docsite/e2e/playground-preview-isolation.spec.ts b/apps/docsite/e2e/playground-preview-isolation.spec.ts
index 201d1f2344..1c589c457c 100644
--- a/apps/docsite/e2e/playground-preview-isolation.spec.ts
+++ b/apps/docsite/e2e/playground-preview-isolation.spec.ts
@@ -153,58 +153,6 @@ function exampleRendering(text: string) {
}
test.describe('playground preview isolation', () => {
- test('survives a deployment-injected cookie probe', async ({page}) => {
- // Vercel adds its Toolbar cookie probe to Next's shared main-app bundle.
- // Insert the same probe immediately after our bootstrap guard but before
- // the Webpack runtime, making this stricter than the deployed ordering.
- await page.route(
- /\/_next\/static\/chunks\/main-app-[^/]+\.js/,
- async route => {
- const response = await route.fetch();
- const body = await response.text();
- const runtimeStart = body.indexOf('(self.webpackChunk_N_E=');
- expect(runtimeStart).toBeGreaterThan(0);
- const cookieProbe = [
- "if (location.pathname === '/playground/preview') {",
- ' void document.cookie;',
- '}',
- ].join('\n');
- await route.fulfill({
- response,
- body: [
- body.slice(0, runtimeStart),
- cookieProbe,
- body.slice(runtimeStart),
- ].join('\n'),
- });
- },
- );
-
- await page.goto('/playground');
-
- await expectPreviewToRender(page, 'Welcome');
- await expect(
- page.getByText('Build error', {exact: true}),
- ).not.toBeVisible();
- expect(
- await currentPreviewFrame(page).evaluate(() => {
- const blocked = (probe: () => unknown) => {
- try {
- probe();
- return false;
- } catch {
- return true;
- }
- };
- return {
- cookie: document.cookie,
- localStorage: blocked(() => window.localStorage),
- parentDocument: blocked(() => window.parent.document),
- };
- }),
- ).toEqual({cookie: '', localStorage: true, parentDocument: true});
- });
-
test('reports a compiler bootstrap failure instead of building forever', async ({
page,
}) => {
diff --git a/apps/docsite/next.config.mjs b/apps/docsite/next.config.mjs
index f107aa82c8..be1363f5be 100644
--- a/apps/docsite/next.config.mjs
+++ b/apps/docsite/next.config.mjs
@@ -2,24 +2,14 @@
/**
* @file Configure the docsite's routes, response headers, and theme resolution.
- * @input Next.js build configuration, the early playground cookie guard, and
- * staged preview-only static exports.
+ * @input Next.js build configuration and staged preview-only static exports.
* @output Docsite routes plus Storybook and Sandbox at /storybook/ and /sandbox/.
- * Client main-app chunks start with the preview's cookie compatibility guard.
* @position Next.js configuration for the existing Vercel docsite deployment.
*/
-import {readFileSync, readdirSync} from 'node:fs';
+import {readdirSync} from 'node:fs';
import {resolve} from 'node:path';
-const playgroundCookieCompatibility = readFileSync(
- resolve(
- import.meta.dirname,
- 'src/app/playground/preview/cookieCompatibility.js',
- ),
- 'utf8',
-);
-
const stagesStaticApps =
process.env.VERCEL_ENV === 'preview' ||
process.env.VERCEL_ENV === 'production';
@@ -94,7 +84,7 @@ const nextConfig = {
},
];
},
- webpack: (config, {isServer, webpack}) => {
+ webpack: config => {
// Webpack's CSS @import resolver doesn't follow package.json "exports".
// Map each theme's /theme.css subpath to the actual dist file.
const themesDir = resolve(import.meta.dirname, '../../packages/themes');
@@ -109,21 +99,6 @@ const nextConfig = {
);
}
- // Vercel can add Toolbar instrumentation to Next's shared main-app entry.
- // Its cookie probe throws before React starts in the playground's opaque
- // frame, so prepend our route-scoped guard to the final client asset. A
- // layout Script is too late: Next emits the async main-app tag first.
- if (!isServer) {
- config.plugins.push(
- new webpack.BannerPlugin({
- banner: playgroundCookieCompatibility,
- entryOnly: true,
- include: /main-app-/,
- raw: true,
- }),
- );
- }
-
return config;
},
};
diff --git a/apps/docsite/src/app/playground/preview/cookieCompatibility.js b/apps/docsite/src/app/playground/preview/cookieCompatibility.js
deleted file mode 100644
index 753732bce4..0000000000
--- a/apps/docsite/src/app/playground/preview/cookieCompatibility.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-/**
- * @file Browser bootstrap guard for deployment tooling that probes cookies.
- * @input The current document and its pathname.
- * @output An inert cookie property only for the opaque-origin playground frame.
- * @position Prepended to the client main-app entry by next.config.mjs so it runs
- * before framework and deployment-injected modules.
- */
-(() => {
- if (globalThis.location.pathname !== '/playground/preview') {
- return;
- }
-
- try {
- void globalThis.document.cookie;
- } catch {
- Object.defineProperty(globalThis.document, 'cookie', {
- configurable: true,
- get: () => '',
- set: () => {},
- });
- }
-})();