From 102a65dd5b81b6de81d4da19a58fba04ed57d793 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Sep 2024 14:53:25 +0200 Subject: [PATCH 1/8] feat(next): TODOs --- packages/astro/src/content/runtime.ts | 1 - packages/astro/src/core/build/internal.ts | 41 ------------------- packages/astro/src/core/build/static-build.ts | 10 ++--- packages/astro/src/core/config/schema.ts | 11 ----- packages/astro/src/core/errors/errors-data.ts | 13 ++++++ packages/astro/src/core/middleware/index.ts | 9 +--- packages/astro/src/core/render-context.ts | 13 +----- .../runtime/client/dev-toolbar/entrypoint.ts | 17 -------- .../runtime/client/dev-toolbar/settings.ts | 7 ---- .../src/runtime/client/dev-toolbar/toolbar.ts | 34 ++++----------- .../client/dev-toolbar/ui-library/button.ts | 2 - .../astro/src/types/public/integrations.ts | 5 ++- 12 files changed, 32 insertions(+), 131 deletions(-) diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index 95d31079029d..5f6cc938c788 100644 --- a/packages/astro/src/content/runtime.ts +++ b/packages/astro/src/content/runtime.ts @@ -228,7 +228,6 @@ export function createGetDataEntryById({ const lazyImport = await getEntryImport(collection, id); - // TODO: AstroError if (!lazyImport) throw new Error(`Entry ${collection} → ${id} was not found.`); const entry = await lazyImport(); diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 4ca1626f9ee6..98fe20c14507 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -228,47 +228,6 @@ export function getPageData( return undefined; } -// TODO: Should be removed in the future. (Astro 5?) -/** - * Map internals.pagesByKeys to a new map with the public key instead of the internal key. - * This function is only used to avoid breaking changes in the Integrations API, after we changed the way - * we identify pages, from the entrypoint component to an internal key. - * If the page component is unique -> the public key is the component path. (old behavior) - * If the page component is shared -> the public key is the internal key. (new behavior) - * The new behavior on shared entrypoint it's not a breaking change, because it was not supported before. - * @param pagesByKeys A map of all page data by their internal key - */ -export function getPageDatasWithPublicKey( - pagesByKeys: Map, -): Map { - // Create a map to store the pages with the public key, mimicking internal.pagesByKeys - const pagesWithPublicKey = new Map(); - - const pagesByComponentsArray = Array.from(pagesByKeys.values()).map((pageData) => { - return { component: pageData.component, pageData: pageData }; - }); - - // Get pages with unique component, and set the public key to the component. - const pagesWithUniqueComponent = pagesByComponentsArray.filter((page) => { - return pagesByComponentsArray.filter((p) => p.component === page.component).length === 1; - }); - - pagesWithUniqueComponent.forEach((page) => { - pagesWithPublicKey.set(page.component, page.pageData); - }); - - // Get pages with shared component, and set the public key to the internal key. - const pagesWithSharedComponent = pagesByComponentsArray.filter((page) => { - return pagesByComponentsArray.filter((p) => p.component === page.component).length > 1; - }); - - pagesWithSharedComponent.forEach((page) => { - pagesWithPublicKey.set(page.pageData.key, page.pageData); - }); - - return pagesWithPublicKey; -} - export function getPageDataByViteID( internals: BuildInternals, viteid: ViteID, diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 20daa6e7b85e..0503543f46c1 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -11,11 +11,7 @@ import { hasAnyContentFlag, reverseSymlink, } from '../../content/utils.js'; -import { - type BuildInternals, - createBuildInternals, - getPageDatasWithPublicKey, -} from '../../core/build/internal.js'; +import { type BuildInternals, createBuildInternals } from '../../core/build/internal.js'; import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js'; import { appendForwardSlash, prependForwardSlash, removeFileExtension } from '../../core/path.js'; import { runHookBuildSetup } from '../../integrations/hooks.js'; @@ -283,7 +279,7 @@ async function ssrBuild( const updatedViteBuildConfig = await runHookBuildSetup({ config: settings.config, - pages: getPageDatasWithPublicKey(internals.pagesByKeys), + pages: internals.pagesByKeys, vite: viteBuildConfig, target: 'server', logger: opts.logger, @@ -344,7 +340,7 @@ async function clientBuild( await runHookBuildSetup({ config: settings.config, - pages: getPageDatasWithPublicKey(internals.pagesByKeys), + pages: internals.pagesByKeys, vite: viteBuildConfig, target: 'client', logger: opts.logger, diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index b89af4f46c60..02f96fe0d093 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -333,17 +333,6 @@ export const AstroConfigSchema = z.object({ transformers: z .custom() .array() - .transform((transformers) => { - for (const transformer of transformers) { - // When updating shikiji to shiki, the `token` property was renamed to `span`. - // We apply the compat here for now until the next Astro major. - // TODO: Remove this in Astro 5.0 - if ((transformer as any).token && !('span' in transformer)) { - transformer.span = (transformer as any).token; - } - } - return transformers; - }) .default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.transformers!), }) .default({}), diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index 09dc51e0f03d..6f6308393150 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -843,6 +843,19 @@ export const LocalsNotAnObject = { hint: 'If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`.', } satisfies ErrorData; +/** + * @docs + * @description + * Thrown when a value is being set as the `locals` field on the Astro global or context. + */ +export const LocalsReassigned = { + name: 'LocalsReassigned', + title: '`locals` must not be reassigned.', + message: '`locals` can not be assigned directly.', + hint: 'Set a `locals` property instead.', +} satisfies ErrorData; + + /** * @docs * @description diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index b79e5c768a75..1d604957b98b 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -98,13 +98,8 @@ function createContext({ } return locals; }, - // We define a custom property, so we can check the value passed to locals - set locals(val) { - if (typeof val !== 'object') { - throw new AstroError(AstroErrorData.LocalsNotAnObject); - } else { - Reflect.set(request, clientLocalsSymbol, val); - } + set locals(_) { + throw new AstroError(AstroErrorData.LocalsReassigned); }, }; return Object.assign(context, { diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index 7ef7a0767d94..13f7c6d777b6 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -19,7 +19,6 @@ import { REWRITE_DIRECTIVE_HEADER_VALUE, ROUTE_TYPE_HEADER, clientAddressSymbol, - clientLocalsSymbol, responseSentSymbol, } from './constants.js'; import { AstroCookies, attachCookiesToResponse } from './cookies/index.js'; @@ -270,16 +269,8 @@ export class RenderContext { get locals() { return renderContext.locals; }, - // TODO(breaking): disallow replacing the locals object - set locals(val) { - if (typeof val !== 'object') { - throw new AstroError(AstroErrorData.LocalsNotAnObject); - } else { - renderContext.locals = val; - // we also put it on the original Request object, - // where the adapter might be expecting to read it after the response. - Reflect.set(this.request, clientLocalsSymbol, val); - } + set locals(_) { + throw new AstroError(AstroErrorData.LocalsReassigned); }, params, get preferredLocale() { diff --git a/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts b/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts index 86c616becb3a..6eca3e3bb26e 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts @@ -51,20 +51,6 @@ document.addEventListener('DOMContentLoaded', async () => { customElements.define('astro-dev-toolbar-select', DevToolbarSelect); customElements.define('astro-dev-toolbar-radio-checkbox', DevToolbarRadioCheckbox); - // Add deprecated names - // TODO: Remove in Astro 5.0 - const deprecated = (Parent: any) => class extends Parent {}; - customElements.define('astro-dev-overlay', deprecated(AstroDevToolbar)); - customElements.define('astro-dev-overlay-window', deprecated(DevToolbarWindow)); - customElements.define('astro-dev-overlay-plugin-canvas', deprecated(DevToolbarCanvas)); - customElements.define('astro-dev-overlay-tooltip', deprecated(DevToolbarTooltip)); - customElements.define('astro-dev-overlay-highlight', deprecated(DevToolbarHighlight)); - customElements.define('astro-dev-overlay-card', deprecated(DevToolbarCard)); - customElements.define('astro-dev-overlay-toggle', deprecated(DevToolbarToggle)); - customElements.define('astro-dev-overlay-button', deprecated(DevToolbarButton)); - customElements.define('astro-dev-overlay-badge', deprecated(DevToolbarBadge)); - customElements.define('astro-dev-overlay-icon', deprecated(DevToolbarIcon)); - overlay = document.createElement('astro-dev-toolbar'); const notificationLevels = ['error', 'warning', 'info'] as const; @@ -121,9 +107,6 @@ document.addEventListener('DOMContentLoaded', async () => { }; eventTarget.addEventListener('toggle-app', onToggleApp); - // Deprecated - // TODO: Remove in Astro 5.0 - eventTarget.addEventListener('toggle-plugin', onToggleApp); return app; }; diff --git a/packages/astro/src/runtime/client/dev-toolbar/settings.ts b/packages/astro/src/runtime/client/dev-toolbar/settings.ts index 2f5eabe6d333..538473326e83 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/settings.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/settings.ts @@ -18,13 +18,6 @@ function getSettings() { let _settings: Settings = { ...defaultSettings }; const toolbarSettings = localStorage.getItem('astro:dev-toolbar:settings'); - // TODO: Remove in Astro 5.0 - const oldSettings = localStorage.getItem('astro:dev-overlay:settings'); - if (oldSettings && !toolbarSettings) { - localStorage.setItem('astro:dev-toolbar:settings', oldSettings); - localStorage.removeItem('astro:dev-overlay:settings'); - } - if (toolbarSettings) { _settings = { ..._settings, ...JSON.parse(toolbarSettings) }; } diff --git a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts index c089664da2ff..7f5f2ac47dd6 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts @@ -16,8 +16,6 @@ export type DevToolbarApp = DevToolbarAppDefinition & { eventTarget: ToolbarAppEventTarget; }; const WS_EVENT_NAME = 'astro-dev-toolbar'; -// TODO: Remove in Astro 5.0 -const WS_EVENT_NAME_DEPRECATED = 'astro-dev-overlay'; const HOVER_DELAY = 2 * 1000; const DEVBAR_HITBOX_ABOVE = 42; @@ -396,8 +394,6 @@ export class AstroDevToolbar extends HTMLElement { if (import.meta.hot) { import.meta.hot.send(`${WS_EVENT_NAME}:${app.id}:initialized`); - // TODO: Remove in Astro 5.0 - import.meta.hot.send(`${WS_EVENT_NAME_DEPRECATED}:${app.id}:initialized`); } } catch (e) { console.error(`Failed to init app ${app.id}, error: ${e}`); @@ -501,28 +497,16 @@ export class AstroDevToolbar extends HTMLElement { appCanvas.removeAttribute('data-active'); } - [ - 'app-toggled', - // Deprecated - // TODO: Remove in Astro 5.0 - 'plugin-toggled', - ].forEach((eventName) => { - app.eventTarget.dispatchEvent( - new CustomEvent(eventName, { - detail: { - state: app.active, - app, - }, - }), - ); - }); + app.eventTarget.dispatchEvent( + new CustomEvent('app-toggled', { + detail: { + state: app.active, + app, + }, + }), + ); - if (import.meta.hot) { - import.meta.hot.send(`${WS_EVENT_NAME}:${app.id}:toggled`, { state: app.active }); - import.meta.hot.send(`${WS_EVENT_NAME_DEPRECATED}:${app.id}:toggled`, { - state: app.active, - }); - } + import.meta.hot?.send(`${WS_EVENT_NAME}:${app.id}:toggled`, { state: app.active }); return true; } diff --git a/packages/astro/src/runtime/client/dev-toolbar/ui-library/button.ts b/packages/astro/src/runtime/client/dev-toolbar/ui-library/button.ts index 0f13c67ec3e7..224ad14c11fc 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/ui-library/button.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/ui-library/button.ts @@ -131,8 +131,6 @@ export class DevToolbarButton extends HTMLElement { cursor: pointer; } - /* TODO: Remove "astro-dev-overlay-icon" in Astro 5.0 */ - ::slotted(astro-dev-overlay-icon), ::slotted(astro-dev-toolbar-icon) { display: inline-block; height: 1em; diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts index 49557c23aa61..9fb557f7399d 100644 --- a/packages/astro/src/types/public/integrations.ts +++ b/packages/astro/src/types/public/integrations.ts @@ -174,8 +174,9 @@ export interface BaseIntegrationHooks { injectScript: (stage: InjectedScriptStage, content: string) => void; injectRoute: (injectRoute: InjectedRoute) => void; addClientDirective: (directive: ClientDirectiveConfig) => void; - // TODO: Deprecate the `string` overload once a few apps have been migrated to the new API. - addDevToolbarApp: (entrypoint: DevToolbarAppEntry | string) => void; + addDevToolbarApp: (entrypoint: DevToolbarAppEntry) => void; + /** @deprecated */ + addDevToolbarApp: (entrypoint: string) => void; addMiddleware: (mid: AstroIntegrationMiddleware) => void; logger: AstroIntegrationLogger; }) => void | Promise; From a46c3ae336543bc7cf778a58479577f3abdb688e Mon Sep 17 00:00:00 2001 From: Princesseuh <3019731+Princesseuh@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:54:07 +0200 Subject: [PATCH 2/8] fix: remove todos --- .../astro/src/assets/utils/node/emitAsset.ts | 2 +- packages/astro/src/core/app/index.ts | 52 +++---------------- .../runtime/client/dev-toolbar/apps/astro.ts | 7 ++- .../client/dev-toolbar/apps/audit/index.ts | 4 +- .../client/dev-toolbar/apps/settings.ts | 4 +- .../runtime/client/dev-toolbar/apps/xray.ts | 7 ++- .../astro/src/types/public/integrations.ts | 2 - packages/astro/src/types/public/toolbar.ts | 26 +--------- 8 files changed, 22 insertions(+), 82 deletions(-) diff --git a/packages/astro/src/assets/utils/node/emitAsset.ts b/packages/astro/src/assets/utils/node/emitAsset.ts index b20ce49330c5..42dd1681f974 100644 --- a/packages/astro/src/assets/utils/node/emitAsset.ts +++ b/packages/astro/src/assets/utils/node/emitAsset.ts @@ -12,7 +12,7 @@ export async function emitESMImage( id: string | undefined, /** @deprecated */ _watchMode: boolean, - // FIX: in Astro 5, this function should not be passed in dev mode at all. + // FIX: in Astro 6, this function should not be passed in dev mode at all. // Or rethink the API so that a function that throws isn't passed through. fileEmitter?: FileEmitter, ): Promise { diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 3ffa5f144647..e3539798ef5d 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -245,48 +245,17 @@ export class App { return pathname; } - async render(request: Request, options?: RenderOptions): Promise; - /** - * @deprecated Instead of passing `RouteData` and locals individually, pass an object with `routeData` and `locals` properties. - * See https://github.com/withastro/astro/pull/9199 for more information. - */ - async render(request: Request, routeData?: RouteData, locals?: object): Promise; - async render( - request: Request, - routeDataOrOptions?: RouteData | RenderOptions, - maybeLocals?: object, - ): Promise { + async render(request: Request, renderOptions?: RenderOptions): Promise { let routeData: RouteData | undefined; let locals: object | undefined; let clientAddress: string | undefined; let addCookieHeader: boolean | undefined; - if ( - routeDataOrOptions && - ('addCookieHeader' in routeDataOrOptions || - 'clientAddress' in routeDataOrOptions || - 'locals' in routeDataOrOptions || - 'routeData' in routeDataOrOptions) - ) { - if ('addCookieHeader' in routeDataOrOptions) { - addCookieHeader = routeDataOrOptions.addCookieHeader; - } - if ('clientAddress' in routeDataOrOptions) { - clientAddress = routeDataOrOptions.clientAddress; - } - if ('routeData' in routeDataOrOptions) { - routeData = routeDataOrOptions.routeData; - } - if ('locals' in routeDataOrOptions) { - locals = routeDataOrOptions.locals; - } - } else { - routeData = routeDataOrOptions as RouteData | undefined; - locals = maybeLocals; - if (routeDataOrOptions || locals) { - this.#logRenderOptionsDeprecationWarning(); - } - } + addCookieHeader = renderOptions?.addCookieHeader; + clientAddress = renderOptions?.clientAddress; + routeData = renderOptions?.routeData; + locals = renderOptions?.locals; + if (routeData) { this.#logger.debug( 'router', @@ -367,15 +336,6 @@ export class App { return response; } - #logRenderOptionsDeprecationWarning() { - if (this.#renderOptionsDeprecationWarningShown) return; - this.#logger.warn( - 'deprecated', - `The adapter ${this.#manifest.adapterName} is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See https://github.com/withastro/astro/pull/9199 for more information.`, - ); - this.#renderOptionsDeprecationWarningShown = true; - } - setCookieHeaders(response: Response) { return getSetCookiesFromResponse(response); } diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts index 12ab602a255e..7995d520910e 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts @@ -1,4 +1,7 @@ -import type { DevToolbarApp, DevToolbarMetadata } from '../../../../types/public/toolbar.js'; +import type { + DevToolbarMetadata, + ResolvedDevToolbarApp, +} from '../../../../types/public/toolbar.js'; import { type Icon, isDefinedIcon } from '../ui-library/icons.js'; import { colorForIntegration, iconForIntegration } from './utils/icons.js'; import { @@ -460,4 +463,4 @@ export default { integrationList.append(fragment); } }, -} satisfies DevToolbarApp; +} satisfies ResolvedDevToolbarApp; diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts index cc58411cf3c4..a292be3dff82 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp } from '../../../../../types/public/toolbar.js'; +import type { ResolvedDevToolbarApp } from '../../../../../types/public/toolbar.js'; import { settings } from '../../settings.js'; import type { DevToolbarHighlight } from '../../ui-library/highlight.js'; import { positionHighlight } from '../utils/highlight.js'; @@ -219,4 +219,4 @@ export default { }); } }, -} satisfies DevToolbarApp; +} satisfies ResolvedDevToolbarApp; diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts index 192e4509b504..547dea287ce6 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp } from '../../../../types/public/toolbar.js'; +import type { ResolvedDevToolbarApp } from '../../../../types/public/toolbar.js'; import { type Settings, settings } from '../settings.js'; import { isValidPlacement, placements } from '../ui-library/window.js'; import { @@ -212,4 +212,4 @@ export default { } } }, -} satisfies DevToolbarApp; +} satisfies ResolvedDevToolbarApp; diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts index fafc8e26d57e..f382bef27d5d 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts @@ -1,5 +1,8 @@ import { escape as escapeHTML } from 'html-escaper'; -import type { DevToolbarApp, DevToolbarMetadata } from '../../../../types/public/toolbar.js'; +import type { + DevToolbarMetadata, + ResolvedDevToolbarApp, +} from '../../../../types/public/toolbar.js'; import type { DevToolbarHighlight } from '../ui-library/highlight.js'; import { attachTooltipToHighlight, @@ -177,4 +180,4 @@ export default { return tooltip; } }, -} satisfies DevToolbarApp; +} satisfies ResolvedDevToolbarApp; diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts index 9fb557f7399d..78c4104f1bd1 100644 --- a/packages/astro/src/types/public/integrations.ts +++ b/packages/astro/src/types/public/integrations.ts @@ -175,8 +175,6 @@ export interface BaseIntegrationHooks { injectRoute: (injectRoute: InjectedRoute) => void; addClientDirective: (directive: ClientDirectiveConfig) => void; addDevToolbarApp: (entrypoint: DevToolbarAppEntry) => void; - /** @deprecated */ - addDevToolbarApp: (entrypoint: string) => void; addMiddleware: (mid: AstroIntegrationMiddleware) => void; logger: AstroIntegrationLogger; }) => void | Promise; diff --git a/packages/astro/src/types/public/toolbar.ts b/packages/astro/src/types/public/toolbar.ts index 7beaab3bb84f..00dc67fba485 100644 --- a/packages/astro/src/types/public/toolbar.ts +++ b/packages/astro/src/types/public/toolbar.ts @@ -50,30 +50,6 @@ export type DevToolbarAppEntry = DevToolbarAppMeta & { // Public API for the dev toolbar export type DevToolbarApp = { - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - id?: string; - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - name?: string; - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - icon?: Icon; init?( canvas: ShadowRoot, app: ToolbarAppEventTarget, @@ -83,7 +59,7 @@ export type DevToolbarApp = { }; // An app that has been loaded and as such contain all of its properties -export type ResolvedDevToolbarApp = DevToolbarAppMeta & Omit; +export type ResolvedDevToolbarApp = DevToolbarAppMeta & DevToolbarApp; export type DevToolbarMetadata = Window & typeof globalThis & { From a1048dddcc57e622422a1558889769166f6c1c62 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 12:42:38 -0400 Subject: [PATCH 3/8] Updates tests to not assign locals --- .../astro/test/fixtures/astro-global/src/middleware.js | 4 ++-- .../test/fixtures/middleware space/src/middleware.js | 8 ++++---- .../test/fixtures/rewrite-custom-404/src/middleware.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/astro/test/fixtures/astro-global/src/middleware.js b/packages/astro/test/fixtures/astro-global/src/middleware.js index 2c549e006036..c2a43cb6bc0a 100644 --- a/packages/astro/test/fixtures/astro-global/src/middleware.js +++ b/packages/astro/test/fixtures/astro-global/src/middleware.js @@ -1,9 +1,9 @@ export function onRequest(ctx, next) { - ctx.locals = { + Object.assign(ctx.locals, { localsPattern: ctx.routePattern, localsPrerendered: ctx.isPrerendered - }; + }); return next() } diff --git a/packages/astro/test/fixtures/middleware space/src/middleware.js b/packages/astro/test/fixtures/middleware space/src/middleware.js index 6310994554ea..ed0503c80cbf 100644 --- a/packages/astro/test/fixtures/middleware space/src/middleware.js +++ b/packages/astro/test/fixtures/middleware space/src/middleware.js @@ -47,9 +47,9 @@ const first = defineMiddleware(async (context, next) => { context.cookies.set('foo', 'bar'); } - context.locals = { + Object.assign(context.locals, { name: 'bar', - }; + }); } return await next(); }); @@ -65,9 +65,9 @@ const second = defineMiddleware(async (context, next) => { const third = defineMiddleware(async (context, next) => { if (context.request.url.includes('/broken-locals')) { - context.locals = { + Object.assign(context.locals, { fn() {}, - }; + }); } else if (context.request.url.includes('/does-nothing')) { return undefined; } diff --git a/packages/astro/test/fixtures/rewrite-custom-404/src/middleware.js b/packages/astro/test/fixtures/rewrite-custom-404/src/middleware.js index 4ca4affe1e57..abde2219d3ce 100644 --- a/packages/astro/test/fixtures/rewrite-custom-404/src/middleware.js +++ b/packages/astro/test/fixtures/rewrite-custom-404/src/middleware.js @@ -2,9 +2,9 @@ export const onRequest = async (context, next) => { if (context.url.pathname.startsWith("/404") || context.url.pathname.startsWith("/500")) { - context.locals = { + Object.assign(context.locals, { interjected: "Interjected" - } + }); } return await next(); } From b81fe46195065439c7fde2b1a6a3a7ae13fe1c75 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 13:22:42 -0400 Subject: [PATCH 4/8] Changesets --- .changeset/blue-sloths-stare.md | 14 ++++++++++++++ .changeset/cool-mangos-shop.md | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .changeset/blue-sloths-stare.md create mode 100644 .changeset/cool-mangos-shop.md diff --git a/.changeset/blue-sloths-stare.md b/.changeset/blue-sloths-stare.md new file mode 100644 index 000000000000..134b45b65881 --- /dev/null +++ b/.changeset/blue-sloths-stare.md @@ -0,0 +1,14 @@ +--- +'astro': patch +--- + +App class now accepts renderOptions + +The signature for `app.render()` has changed, and the second argument is now an options object called `renderOptions`. This allows you greater customization of rendering than with the old signature. + +The renderOptions are: + +- `addCookieHeader`: Determines whether Astro will set the `Set-Cookie` header, otherwise the adapter is expected to do so itself. +- `clientAddress`: The client IP address used to set `Astro.clientAddress`. +- `locals`: An object of locals that's set to `Astro.locals`. +- `routeData`: An object specifying the route to use. diff --git a/.changeset/cool-mangos-shop.md b/.changeset/cool-mangos-shop.md new file mode 100644 index 000000000000..5175c39e5908 --- /dev/null +++ b/.changeset/cool-mangos-shop.md @@ -0,0 +1,25 @@ +--- +'astro': major +--- + +The locals object can no longer be overridden + +Middleware, API endpoints, and pages can no longer override the `locals` object in its entirety. You can still append locals onto the object, but you can not replace the entire object, wiping out old values. + +If you were previously overwriting like so: + +```js +ctx.locals = { + one: 1, + two: 2 +} +``` + +This can be changed to an assignment on the existing object instead: + +```js +Object.assign(ctx.locals, { + one: 1, + two: 2 +}) +``` From 50bc4f863f9188ab1af370198124aa9e211eb47d Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 13:53:30 -0400 Subject: [PATCH 5/8] Update .changeset/cool-mangos-shop.md Co-authored-by: Sarah Rainsberger --- .changeset/cool-mangos-shop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/cool-mangos-shop.md b/.changeset/cool-mangos-shop.md index 5175c39e5908..893ed22e20f4 100644 --- a/.changeset/cool-mangos-shop.md +++ b/.changeset/cool-mangos-shop.md @@ -2,9 +2,9 @@ 'astro': major --- -The locals object can no longer be overridden +The `locals` object can no longer be overridden -Middleware, API endpoints, and pages can no longer override the `locals` object in its entirety. You can still append locals onto the object, but you can not replace the entire object, wiping out old values. +Middleware, API endpoints, and pages can no longer override the `locals` object in its entirety. You can still append values onto the object, but you can not replace the entire object and delete its existing values. If you were previously overwriting like so: From 8d7698744dedb930e1342222dbac2818d380c559 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 13:53:40 -0400 Subject: [PATCH 6/8] Update .changeset/blue-sloths-stare.md Co-authored-by: Sarah Rainsberger --- .changeset/blue-sloths-stare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/blue-sloths-stare.md b/.changeset/blue-sloths-stare.md index 134b45b65881..23ea86f9e247 100644 --- a/.changeset/blue-sloths-stare.md +++ b/.changeset/blue-sloths-stare.md @@ -4,7 +4,7 @@ App class now accepts renderOptions -The signature for `app.render()` has changed, and the second argument is now an options object called `renderOptions`. This allows you greater customization of rendering than with the old signature. +The signature for `app.render()` has changed, and the second argument is now an options object called `renderOptions` with more options for customizing rendering. The renderOptions are: From 5b011e4d1608a1a3fce3368e92d9375e22f0c5b6 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 13:53:50 -0400 Subject: [PATCH 7/8] Update .changeset/blue-sloths-stare.md Co-authored-by: Sarah Rainsberger --- .changeset/blue-sloths-stare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/blue-sloths-stare.md b/.changeset/blue-sloths-stare.md index 23ea86f9e247..f1b0633ce5ab 100644 --- a/.changeset/blue-sloths-stare.md +++ b/.changeset/blue-sloths-stare.md @@ -6,7 +6,7 @@ App class now accepts renderOptions The signature for `app.render()` has changed, and the second argument is now an options object called `renderOptions` with more options for customizing rendering. -The renderOptions are: +The `renderOptions` are: - `addCookieHeader`: Determines whether Astro will set the `Set-Cookie` header, otherwise the adapter is expected to do so itself. - `clientAddress`: The client IP address used to set `Astro.clientAddress`. From f79a6a5e6b37557ad62f61a6514457f97540ea57 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 13 Sep 2024 13:59:56 -0400 Subject: [PATCH 8/8] Update .changeset/blue-sloths-stare.md --- .changeset/blue-sloths-stare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/blue-sloths-stare.md b/.changeset/blue-sloths-stare.md index f1b0633ce5ab..53ab43b2ef8a 100644 --- a/.changeset/blue-sloths-stare.md +++ b/.changeset/blue-sloths-stare.md @@ -2,7 +2,7 @@ 'astro': patch --- -App class now accepts renderOptions +`render()` signature now takes `renderOptions` as 2nd argument The signature for `app.render()` has changed, and the second argument is now an options object called `renderOptions` with more options for customizing rendering.