@astrojs/mdx 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- @astrojs/mdx:build: cache hit, replaying output 9de770958d53d2f8
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.10.0 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4443](https://github.com/withastro/astro/pull/4443) [`adb207979`](https://github.com/withastro/astro/commit/adb20797962c280d4d38f335f577fd52a1b48d4b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix MDX style imports when layout is not applied
8
+
9
+ * [#4428](https://github.com/withastro/astro/pull/4428) [`a2414bf59`](https://github.com/withastro/astro/commit/a2414bf59e2e2cd633aece68e724401c4ad281b9) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix dev server reload performance when globbing from an MDX layout
10
+
3
11
  ## 0.10.0
4
12
 
5
13
  ### Minor Changes
@@ -18,9 +18,9 @@ function rehypeApplyFrontmatterExport(pageFrontmatter) {
18
18
  exportNodes.unshift(
19
19
  jsToTreeNode(
20
20
  `import { jsx as layoutJsx } from 'astro/jsx-runtime';
21
- import Layout from ${JSON.stringify(frontmatter.layout)};
22
21
 
23
- export default function ({ children }) {
22
+ export default async function ({ children }) {
23
+ const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
24
24
  const { layout, ...content } = frontmatter;
25
25
  content.file = file;
26
26
  content.url = url;
package/dist/index.js CHANGED
@@ -85,6 +85,8 @@ function mdx(mdxOptions = {}) {
85
85
  transform(code, id) {
86
86
  if (!id.endsWith(".mdx"))
87
87
  return;
88
+ code += `
89
+ MDXContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
88
90
  const [, moduleExports] = parseESM(code);
89
91
  const { fileUrl, fileId } = getFileInfo(id, config);
90
92
  if (!moduleExports.includes("url")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/mdx",
3
3
  "description": "Use MDX within Astro",
4
- "version": "0.10.0",
4
+ "version": "0.10.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -42,7 +42,7 @@
42
42
  "@types/chai": "^4.3.1",
43
43
  "@types/mocha": "^9.1.1",
44
44
  "@types/yargs-parser": "^21.0.0",
45
- "astro": "1.0.6",
45
+ "astro": "1.0.8",
46
46
  "astro-scripts": "0.0.7",
47
47
  "chai": "^4.3.6",
48
48
  "linkedom": "^0.14.12",
@@ -20,13 +20,17 @@ export function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any
20
20
  jsToTreeNode(`export const ${EXPORT_NAME} = ${JSON.stringify(frontmatter)};`),
21
21
  ];
22
22
  if (frontmatter.layout) {
23
+ // NOTE(bholmesdev) 08-22-2022
24
+ // Using an async layout import (i.e. `const Layout = (await import...)`)
25
+ // Preserves the dev server import cache when globbing a large set of MDX files
26
+ // Full explanation: 'https://github.com/withastro/astro/pull/4428'
23
27
  exportNodes.unshift(
24
28
  jsToTreeNode(
25
29
  /** @see 'vite-plugin-markdown' for layout props reference */
26
30
  `import { jsx as layoutJsx } from 'astro/jsx-runtime';
27
- import Layout from ${JSON.stringify(frontmatter.layout)};
28
31
 
29
- export default function ({ children }) {
32
+ export default async function ({ children }) {
33
+ const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
30
34
  const { layout, ...content } = frontmatter;
31
35
  content.file = file;
32
36
  content.url = url;
package/src/index.ts CHANGED
@@ -119,6 +119,11 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
119
119
  // These transforms must happen *after* JSX runtime transformations
120
120
  transform(code, id) {
121
121
  if (!id.endsWith('.mdx')) return;
122
+
123
+ // Ensures styles and scripts are injected into a `<head>`
124
+ // When a layout is not applied
125
+ code += `\nMDXContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
126
+
122
127
  const [, moduleExports] = parseESM(code);
123
128
 
124
129
  const { fileUrl, fileId } = getFileInfo(id, config);
@@ -1 +1,3 @@
1
+ import '../styles.css'
2
+
1
3
  # Hello page!
@@ -0,0 +1,3 @@
1
+ p {
2
+ color: red;
3
+ }
@@ -26,6 +26,15 @@ describe('MDX Page', () => {
26
26
 
27
27
  expect(h1.textContent).to.equal('Hello page!');
28
28
  });
29
+
30
+ it('injects style imports when layout is not applied', async () => {
31
+ const html = await fixture.readFile('/index.html');
32
+ const { document } = parseHTML(html);
33
+
34
+ const stylesheet = document.querySelector('link[rel="stylesheet"]');
35
+
36
+ expect(stylesheet).to.not.be.null;
37
+ });
29
38
  });
30
39
 
31
40
  describe('dev', () => {