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

Add private addPageExtension hook #3628

Merged
merged 2 commits into from
Jun 20, 2022
Merged

Add private addPageExtension hook #3628

merged 2 commits into from
Jun 20, 2022

Conversation

natemoo-re
Copy link
Member

Changes

  • Internal change to add addPageExtension hook to integrations
  • Includes a few other changes to allow non-standard pages to be wired up to the build.
    • These will typically need their own renderer that returns HTML.
  • No changeset, not a public change

Testing

Test added

Docs

Not a public change

@changeset-bot
Copy link

changeset-bot bot commented Jun 17, 2022

⚠️ No Changeset found

Latest commit: b99f21e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 17, 2022
// Otherwise, create a unique id for this set of hoisted scripts
moduleId = `/astro/hoisted.js?q=${uniqueHoistedIds.size}`;
uniqueHoistedIds.set(uniqueHoistedId, moduleId);
if (metadata) {
Copy link
Member Author

Choose a reason for hiding this comment

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

All this noise is just moving anything that accesses metadata inside an if (metadata) block. With custom pages, metadata might not be defined.

Comment on lines +148 to +154
if (!Component.isAstroComponentFactory) {
const props: Record<string, any> = { ...(pageProps ?? {}), 'server:root': true };
const html = await renderComponent(result, Component.name, Component, props, null);
page = {
type: 'html',
html: html.toString()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

If the module exports a non-astro file, we pass it through our component pipeline instead, which will use any provided renderers to render the component

Comment on lines +55 to +63
// Semi-private `addPageExtension` hook
Object.defineProperty(hooks, 'addPageExtension', {
value: (...input: (string|string[])[]) => {
const exts = (input.flat(Infinity) as string[]).map(ext => `.${ext.replace(/^\./, '')}`);
updatedConfig._ctx.pageExtensions.push(...exts);
},
writable: false,
enumerable: false
})
Copy link
Member Author

Choose a reason for hiding this comment

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

Not that private, but it works! It is intentionally not enumerable or exposed in the types, only there if you're looking for it.

packages/astro/src/runtime/server/index.ts Outdated Show resolved Hide resolved
Comment on lines +320 to +322
if (isPage) {
return html;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For hydration to work, we need to avoid stripping out astro-fragment on the top-level page, so we inject a server:root prop to track that.

packages/astro/src/core/render/core.ts Show resolved Hide resolved
@natemoo-re natemoo-re changed the title Add private addPageExtensions hook Add private addPageExtension hook Jun 20, 2022
@matthewp
Copy link
Contributor

I think I know what this is for...

a dog looking around the corner

@@ -57,46 +57,54 @@ export async function staticBuild(opts: StaticBuildOptions) {
const [renderers, mod] = pageData.preload;
const metadata = mod.$$metadata;

// Track client:only usage so we can map their CSS back to the Page they are used in.
const clientOnlys = Array.from(metadata.clientOnlyComponentPaths());
Copy link
Contributor

Choose a reason for hiding this comment

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

There's going to be merge conflicts after #3625 is merged. However all of this code goes away, so I think your changes won't be needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, noticed this! Was glad to see this going away.

@natemoo-re natemoo-re merged commit 8e3e489 into main Jun 20, 2022
@natemoo-re natemoo-re deleted the feat/page-extensions branch June 20, 2022 19:05
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* feat: add private `addPageExtensions` hook

* chore: remove renderer binding

Co-authored-by: Nate Moore <nate@astro.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants