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: Add a dev overlay #8757

Merged
merged 36 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66f7b5a
feat: initial commit for dev overlay
Princesseuh Oct 5, 2023
5bb1398
Merge branch 'main' into feat/dev-overlay
Princesseuh Oct 5, 2023
4ba8b5c
fix: lockfile
Princesseuh Oct 5, 2023
85d1d60
fix: build
Princesseuh Oct 5, 2023
8529860
Merge branch 'main' into feat/dev-overlay
Princesseuh Oct 11, 2023
a14fb9e
chore: get ci in a better state
Princesseuh Oct 11, 2023
a5d734a
feat: client-server communication
Princesseuh Oct 12, 2023
97cac13
fix: better position for xray
Princesseuh Oct 13, 2023
25a922e
refactor: move icons to separate files
Princesseuh Oct 16, 2023
6ff04c4
refactor: cleanup components
Princesseuh Oct 17, 2023
44f4fb1
feat: home screen
Princesseuh Oct 19, 2023
9d1438e
refactor: rename icon
Princesseuh Oct 20, 2023
c9935cd
feat: flag the feature
Princesseuh Oct 20, 2023
69fcb81
fix: cleanup
Princesseuh Oct 23, 2023
78b368b
fix: lockfile
Princesseuh Oct 23, 2023
52c10a9
Merge branch 'main' into feat/dev-overlay
Princesseuh Oct 23, 2023
6716c80
feat: minimize button
Princesseuh Oct 24, 2023
8082237
Update packages/astro/src/@types/astro.ts
Princesseuh Oct 24, 2023
f143ae8
refactor: cleanup
Princesseuh Oct 24, 2023
a8fc4e1
feat: add ability to go to component for hydrated components
Princesseuh Oct 24, 2023
a57ea7e
refactor: consistent logic between audit and xray
Princesseuh Oct 24, 2023
7788168
chore: changeset
Princesseuh Oct 24, 2023
e8978fe
Merge branch 'main' into feat/dev-overlay
Princesseuh Oct 24, 2023
7ab5f5f
Apply suggestions from code review
Princesseuh Oct 25, 2023
a07198c
fix: unchonky the SVGs
Princesseuh Oct 25, 2023
5fd5731
fix: button a11y
Princesseuh Oct 25, 2023
87fe5c3
refactor: move common highlight utilities to a dedicated file
Princesseuh Oct 25, 2023
ed317ff
Merge branch 'main' into feat/dev-overlay
Princesseuh Oct 25, 2023
327bc02
fix: allow tabbing on highlights
Princesseuh Oct 25, 2023
5860213
fix: allow tooltip clickable sections to be tabbed to
Princesseuh Oct 25, 2023
950a24e
feat: allow using defined icons as plugin icons
Princesseuh Oct 25, 2023
7a655d2
refactor: remove unnecessary resolve
Princesseuh Oct 25, 2023
cedfbca
Update .changeset/large-stingrays-fry.md
Princesseuh Oct 25, 2023
06209b0
Update .changeset/large-stingrays-fry.md
Princesseuh Oct 25, 2023
36150e2
nit: use append
Princesseuh Oct 25, 2023
8f444a5
style: small tweaks to minimize button styling
Princesseuh Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/large-stingrays-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'astro': minor
---

Add an experimental Dev Overlay. This overlay allows you to inspect your page islands, see helpful audits on performance and accessibility, and more.
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved

```ts
// astro.config.mjs
export default {
experimental: {
devOverlay: true
}
};
```
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { builtinModules } = require('module');

/** @type {import("@types/eslint").Linter.Config} */
module.exports = {
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
Expand Down Expand Up @@ -74,6 +76,12 @@ module.exports = {
],
},
},
{
files: ['packages/astro/src/runtime/client/**/*.ts'],
env: {
browser: true,
},
},
{
files: ['packages/**/test/*.js', 'packages/**/*.js'],
env: {
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/bundle-size.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async function bundle(files) {
sourcemap: false,
target: ['es2018'],
outdir: 'out',
external: ['astro:*'],
natemoo-re marked this conversation as resolved.
Show resolved Hide resolved
metafile: true,
})

Expand Down
36 changes: 36 additions & 0 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { TSConfig } from '../core/config/tsconfig.js';
import type { AstroCookies } from '../core/cookies/index.js';
import type { ResponseWithEncoding } from '../core/endpoint/index.js';
import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
import type { Icon } from '../runtime/client/dev-overlay/ui-library/icons.js';
import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server/index.js';
import type { OmitIndexSignature, Simplify } from '../type-utils.js';
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
Expand Down Expand Up @@ -1351,6 +1352,25 @@ export interface AstroUserConfig {
* ```
*/
optimizeHoistedScript?: boolean;

/**
* @docs
* @name experimental.devOverlay
* @type {boolean}
* @default `false`
* @version 3.4.0
* @description
* Enable a dev overlay in development mode. This overlay allows you to inspect your page islands, see helpful audits on performance and accessibility, and more.
*
* ```js
* {
* experimental: {
* devOverlay: true,
* },
* }
* ```
*/
devOverlay?: boolean;
natemoo-re marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -1524,6 +1544,7 @@ export interface AstroSettings {
* Map of directive name (e.g. `load`) to the directive script code
*/
clientDirectives: Map<string, string>;
devOverlayPlugins: string[];
tsConfig: TSConfig | undefined;
tsConfigPath: string | undefined;
watchFiles: string[];
Expand Down Expand Up @@ -2049,6 +2070,7 @@ export interface AstroIntegration {
injectScript: (stage: InjectedScriptStage, content: string) => void;
injectRoute: (injectRoute: InjectedRoute) => void;
addClientDirective: (directive: ClientDirectiveConfig) => void;
addDevOverlayPlugin: (entrypoint: string) => void;
logger: AstroIntegrationLogger;
// TODO: Add support for `injectElement()` for full HTML element injection, not just scripts.
// This may require some refactoring of `scripts`, `styles`, and `links` into something
Expand Down Expand Up @@ -2284,3 +2306,17 @@ export interface ClientDirectiveConfig {
name: string;
entrypoint: string;
}

export interface DevOverlayPlugin {
id: string;
name: string;
icon: Icon;
init?(canvas: ShadowRoot, eventTarget: EventTarget): void | Promise<void>;
}

export type DevOverlayMetadata = Window &
typeof globalThis & {
__astro_dev_overlay__: {
root: string;
};
};
2 changes: 2 additions & 0 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const ASTRO_CONFIG_DEFAULTS = {
redirects: {},
experimental: {
optimizeHoistedScript: false,
devOverlay: false,
},
} satisfies AstroUserConfig & { server: { open: boolean } };

Expand Down Expand Up @@ -297,6 +298,7 @@ export const AstroConfigSchema = z.object({
.boolean()
.optional()
.default(ASTRO_CONFIG_DEFAULTS.experimental.optimizeHoistedScript),
devOverlay: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.devOverlay),
})
.strict(
`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for a list of all current experiments.`
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
scripts: [],
clientDirectives: getDefaultClientDirectives(),
watchFiles: [],
devOverlayPlugins: [],
timer: new AstroTimer(),
};
}
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.j
import { vitePluginAstroServer } from '../vite-plugin-astro-server/index.js';
import astroVitePlugin from '../vite-plugin-astro/index.js';
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
import astroDevOverlay from '../vite-plugin-dev-overlay/vite-plugin-dev-overlay.js';
import envVitePlugin from '../vite-plugin-env/index.js';
import astroHeadPlugin from '../vite-plugin-head/index.js';
import htmlVitePlugin from '../vite-plugin-html/index.js';
Expand Down Expand Up @@ -134,6 +135,7 @@ export async function createVite(
vitePluginSSRManifest(),
astroAssetsPlugin({ settings, logger, mode }),
astroTransitions(),
astroDevOverlay({ settings, logger }),
],
publicDir: fileURLToPath(settings.config.publicDir),
root: fileURLToPath(settings.config.root),
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export async function runHookConfigSetup({
addWatchFile: (path) => {
updatedSettings.watchFiles.push(path instanceof URL ? fileURLToPath(path) : path);
},
addDevOverlayPlugin: (entrypoint) => {
updatedSettings.devOverlayPlugins.push(entrypoint);
},
addClientDirective: ({ name, entrypoint }) => {
bluwy marked this conversation as resolved.
Show resolved Hide resolved
if (updatedSettings.clientDirectives.has(name) || addedClientDirectives.has(name)) {
throw new Error(
Expand Down
Loading
Loading