Skip to content

fix: bundle client-side code for components used in .md pages#78

Merged
matthewp merged 1 commit into
mainfrom
bundle-md-imports
Apr 13, 2021
Merged

fix: bundle client-side code for components used in .md pages#78
matthewp merged 1 commit into
mainfrom
bundle-md-imports

Conversation

@mxmul
Copy link
Copy Markdown
Contributor

@mxmul mxmul commented Apr 11, 2021

Changes

The client-side code for hydrated components in .md pages wasn't being bundled properly. This worked fine in dev, but in a production build you would end up with a broken import and no JS emitted:

$ cat test/fixtures/astro-markdown/_site/complex/index.html
<!doctype html><html ><head ></head><body ><div class="container astro-4v5fIax1"><section class="astro-yjJUBnmm"><h2 id="interesting-topic"class="astro-yjJUBnmm">Interesting Topic</h2><div id="test">Hello world</div><div data-astro-id="7083003086872237"><button>0</button></div>
<script type="module">(async () => {
const [{default: Component}, { render, h }] = await Promise.all([import("/_astro/components/Counter.js"), import("/_snowpack/pkg/preact.v10.5.13.js")]);
render(h(Component, {}), document.querySelector('[data-astro-id="7083003086872237"]'))
})()</script></section></div></body></html>

$ stat test/fixtures/astro-markdown/_site/_astro/components/Counter.js
stat: test/fixtures/astro-markdown/_site/_astro/components/Counter.js: stat: No such file or directory

I updated the bundling code to also parse dynamic imports out of .md pages.

Testing

Added an integration test.

  • Tests are passing
  • Tests updated where necessary

Docs

  • Docs / READMEs updated
  • Code comments added where helpful

@mxmul mxmul force-pushed the bundle-md-imports branch from e592fab to 9941b4c Compare April 11, 2021 20:13
@matthewp
Copy link
Copy Markdown
Contributor

Thanks so much! I'll take a look at why tests are breaking in the morning and hopefully get this in.

@matthewp
Copy link
Copy Markdown
Contributor

@mxmul if you can rebase with main at your convenience it should get the tests to pass. Thanks again!

@mxmul mxmul force-pushed the bundle-md-imports branch from 60cad9c to 593fe20 Compare April 12, 2021 15:36
@mxmul
Copy link
Copy Markdown
Contributor Author

mxmul commented Apr 12, 2021

@matthewp done! CI is green now

@matthewp
Copy link
Copy Markdown
Contributor

Thanks! This is an awesome fix.

@matthewp matthewp merged commit ac22d94 into main Apr 13, 2021
@matthewp matthewp deleted the bundle-md-imports branch April 13, 2021 17:04
Princesseuh pushed a commit that referenced this pull request Oct 20, 2025
* Add DiagnosticSeverity export

This adds the DiagnosticSeverity as an export, as this is needed in
`astro check`.

* Adds a changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants