Skip to content

Commit

Permalink
Merge branch 'main' into pr/JoshuaKGoldberg/7425
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 3, 2023
2 parents d92c4bc + 94a1529 commit c5330c3
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 140 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-ants-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/image": patch
---

fix: make `Picture` generate valid dev URLs
5 changes: 5 additions & 0 deletions .changeset/giant-crews-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix bug when using `define:vars` with a `style` object
5 changes: 5 additions & 0 deletions .changeset/grumpy-readers-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Add `Props` generic for `APIRoute` type
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^1.5.0",
"@astrojs/compiler": "^1.5.3",
"@astrojs/internal-helpers": "^0.1.1",
"@astrojs/language-server": "^1.0.0",
"@astrojs/markdown-remark": "^2.2.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1764,21 +1764,21 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
locals: App.Locals;
}

export type Props = Record<string, unknown>;

export interface EndpointOutput {
body: Body;
encoding?: BufferEncoding;
}

export type APIRoute = (
context: APIContext
export type APIRoute<Props extends Record<string, any> = Record<string, any>> = (
context: APIContext<Props>
) => EndpointOutput | Response | Promise<EndpointOutput | Response>;

export interface EndpointHandler {
[method: string]: APIRoute | ((params: Params, request: Request) => EndpointOutput | Response);
}

export type Props = Record<string, unknown>;

export interface AstroRenderer {
/** Name of the renderer. */
name: string;
Expand Down
11 changes: 9 additions & 2 deletions packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ Make sure to use the static attribute syntax (\`${key}={value}\`) instead of the
}

// support object styles for better JSX compat
if (key === 'style' && !(value instanceof HTMLString) && typeof value === 'object') {
return markHTMLString(` ${key}="${toAttributeString(toStyleString(value), shouldEscape)}"`);
if (key === 'style' && !(value instanceof HTMLString)) {
if (Array.isArray(value) && value.length === 2) {
return markHTMLString(
` ${key}="${toAttributeString(`${toStyleString(value[0])};${value[1]}`, shouldEscape)}"`
);
}
if (typeof value === 'object') {
return markHTMLString(` ${key}="${toAttributeString(toStyleString(value), shouldEscape)}"`);
}
}

// support `className` for better JSX compat
Expand Down
13 changes: 13 additions & 0 deletions packages/astro/test/astro-directives.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ describe('Directives', async () => {
expect($('h1').attr('style').toString()).to.include('--textColor: red;');
});

it('Properly handles define:vars on style elements with style object', async () => {
const html = await fixture.readFile('/define-vars/index.html');
const $ = cheerio.load(html);

// All styles should be bundled
expect($('style')).to.have.lengthOf(0);

// Inject style attribute on top-level element in page
expect($('#compound-style').attr('style').toString()).to.include(
'color:var(--fg);--fg: black;--bg: white;'
);
});

it('set:html', async () => {
const html = await fixture.readFile('/set-html/index.html');
const $ = cheerio.load(html);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let undef: undefined;
<script id="inline-5" define:vars={{ undef }}>
console.log(undef);
</script>

<div id="compound-style" style={{ color: `var(--fg)` }}></div>
<Title />
</body>
</html>
5 changes: 2 additions & 3 deletions packages/integrations/alpinejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ npm install alpinejs @types/alpinejs

Then, apply this integration to your `astro.config.*` file using the `integrations` property:

**`astro.config.mjs`**

```js ins={2} "alpine()"
```js ins={3} "alpine()"
// astro.config.mjs
import { defineConfig } from 'astro/config';
import alpine from '@astrojs/alpinejs';

Expand Down
3 changes: 1 addition & 2 deletions packages/integrations/deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs
To configure this adapter, pass an object to the `deno()` function call in `astro.config.mjs`.
**`astro.config.mjs`**
```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';
Expand Down
19 changes: 7 additions & 12 deletions packages/integrations/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ npm install @astrojs/image

Then, apply this integration to your `astro.config.*` file using the `integrations` property:

**`astro.config.mjs`**

```js ins={2} "image()"
```js ins={3} "image()"
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';

Expand All @@ -85,9 +84,8 @@ npm install sharp

Then, update the integration in your `astro.config.*` file to use the built-in `sharp` image transformer.

**`astro.config.mjs`**

```js ins={7}
```js ins={8}
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';

Expand Down Expand Up @@ -478,9 +476,8 @@ The integration can be configured to run with a different image service, either

The `serviceEntryPoint` should resolve to the image service installed from NPM. The default entry point is `@astrojs/image/squoosh`, which resolves to the entry point exported from this integration's `package.json`.

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';

Expand All @@ -498,9 +495,8 @@ export default defineConfig({

The `logLevel` controls can be used to control how much detail is logged by the integration during builds. This may be useful to track down a specific image or transformation that is taking a long time to build.

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';

Expand All @@ -523,9 +519,8 @@ Local images will be cached for 1 year and invalidated when the original image f

By default, transformed images will be cached to `./node_modules/.astro/image`. This can be configured in the integration's config options.

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/lib/get-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function getPicture(params: GetPictureParams): Promise<GetPictureRe
image = img;
}

return `${encodeURI(img.src ?? '')} ${width}w`;
return `${img.src?.replaceAll(' ', encodeURI)} ${width}w`;
})
);

Expand Down
12 changes: 12 additions & 0 deletions packages/integrations/image/test/picture-ssg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ describe('SSG pictures with subpath - dev', function () {
const src = image.attr('src');
const [route, params] = src.split('?');

for (const srcset of picture
.children('source')
.map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];

const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}

expect(route).to.equal(url);

const searchParams = new URLSearchParams(params);
Expand Down
12 changes: 12 additions & 0 deletions packages/integrations/image/test/picture-ssr-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ describe('SSR pictures with subpath - build', function () {
const src = image.attr('src');
const [route, params] = src.split('?');

for (const srcset of picture
.children('source')
.map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];

const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}

expect(route).to.equal(url);

const searchParams = new URLSearchParams(params);
Expand Down
12 changes: 12 additions & 0 deletions packages/integrations/image/test/picture-ssr-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ describe('SSR pictures - dev', function () {
const src = image.attr('src');
const [route, params] = src.split('?');

for (const srcset of picture
.children('source')
.map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];

const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}

expect(route).to.equal(url);

const searchParams = new URLSearchParams(params);
Expand Down
11 changes: 4 additions & 7 deletions packages/integrations/lit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ npm install lit @webcomponents/template-shadowroot

Now, apply this integration to your `astro.config.*` file using the `integrations` property:

**`astro.config.mjs`**

```js ins={2} "lit()"
```js ins={3} "lit()"
// astro.config.mjs
import { defineConfig } from 'astro/config';
import lit from '@astrojs/lit';

Expand All @@ -66,9 +65,8 @@ However, there's a key difference with Lit _custom elements_ over conventional _

Astro needs to know which tag is associated with which component script. We expose this through exporting a `tagName` variable from the component script. It looks like this:

**`src/components/my-element.js`**

```js
// src/components/my-element.js
import { LitElement, html } from 'lit';

const tagName = 'my-element';
Expand All @@ -86,10 +84,9 @@ customElements.define(tagName, MyElement);
In your Astro template import this component as a side-effect and use the element.

**`src/pages/index.astro`**

```astro
---
// src/pages/index.astro
import { MyElement } from '../components/my-element.js';
---
Expand Down
5 changes: 2 additions & 3 deletions packages/integrations/markdoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ npm install @astrojs/markdoc

Then, apply this integration to your `astro.config.*` file using the `integrations` property:

**`astro.config.mjs`**

```js ins={2} "markdoc()"
```js ins={3} "markdoc()"
// astro.config.mjs
import { defineConfig } from 'astro/config';
import markdoc from '@astrojs/markdoc';

Expand Down
20 changes: 7 additions & 13 deletions packages/integrations/mdx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ npm install @astrojs/mdx

Then, apply this integration to your `astro.config.*` file using the `integrations` property:

**`astro.config.mjs`**

```js ins={2} "mdx()"
```js ins={3} "mdx()"
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';

Expand Down Expand Up @@ -95,9 +94,8 @@ All [`markdown` configuration options](https://docs.astro.build/en/reference/con
There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.build/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be overridden for MDX files specifically.
:::

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import remarkToc from 'remark-toc';
Expand Down Expand Up @@ -132,9 +130,8 @@ MDX will extend [your project's existing Markdown configuration](https://docs.as

For example, say you need to disable GitHub-Flavored Markdown and apply a different set of remark plugins for MDX files. You can apply these options like so, with `extendMarkdownConfig` enabled by default:

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';

Expand All @@ -160,9 +157,8 @@ export default defineConfig({

You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';

Expand Down Expand Up @@ -194,9 +190,8 @@ This is an optional configuration setting to optimize the MDX output for faster

This is disabled by default. To enable MDX optimization, add the following to your MDX integration configuration:

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';

Expand Down Expand Up @@ -230,9 +225,8 @@ import Heading from '../Heading.astro';

To configure optimization for this using the `customComponentNames` property, specify an array of HTML element names that should be treated as custom components:

**`astro.config.mjs`**

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';

Expand Down
Loading

0 comments on commit c5330c3

Please sign in to comment.