Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next): TODOs #11987

Merged
merged 11 commits into from
Sep 13, 2024
1 change: 0 additions & 1 deletion packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export function createGetDataEntryById({

const lazyImport = await getEntryImport(collection, id);

// TODO: AstroError
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed in Astro 6.0, not worth doing it now

if (!lazyImport) throw new Error(`Entry ${collection} → ${id} was not found.`);
const entry = await lazyImport();

Expand Down
41 changes: 0 additions & 41 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PageBuildData>,
): Map<string, PageBuildData> {
// Create a map to store the pages with the public key, mimicking internal.pagesByKeys
const pagesWithPublicKey = new Map<string, PageBuildData>();

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,
Expand Down
10 changes: 3 additions & 7 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,6 @@ export const AstroConfigSchema = z.object({
transformers: z
.custom<ShikiTransformer>()
.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({}),
Expand Down
13 changes: 13 additions & 0 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions packages/astro/src/core/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
13 changes: 2 additions & 11 deletions packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down
17 changes: 0 additions & 17 deletions packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
7 changes: 0 additions & 7 deletions packages/astro/src/runtime/client/dev-toolbar/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
}
Expand Down
34 changes: 9 additions & 25 deletions packages/astro/src/runtime/client/dev-toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions packages/astro/src/types/public/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
addMiddleware: (mid: AstroIntegrationMiddleware) => void;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
Expand Down
Loading