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

Allow missing outputPath when running under Serverless #18

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

ashur
Copy link
Contributor

@ashur ashur commented Nov 25, 2023

Summary

This PR updates the bundle transform function, allowing page.outputPath to be falsy when running under Eleventy Serverless.

This fixes an issue that causes placeholder strings to be rendered in Eleventy Serverless responses.

Details & Context

When using the shipping version of the bundler plugin in an Eleventy Serverless context, placeholder values are unexpectedly rendered to the resulting page. For example:

{# src/_includes/layouts/base.njk #}

<!-- Here comes a bundle result! -->
{%- getBundle "html", "head-preconnect" -%}

results in an un-transformed placeholder rendered in the response:

<!-- Here comes a bundle result! -->
/*__EleventyBundle:get:html:head-preconnect:EleventyBundle__*/

This appears to be the result of the test for page.outputPath:

eleventyConfig.addTransform("@11ty/eleventy-bundle", async function(content) {
if(!this.page.outputPath || typeof content !== "string") {
return content;
}

which is false when the page is rendered by Eleventy Serverless:

{
  date: 2023-11-24T20:16:56.706Z,
  inputPath: './src/cms/preview.njk',
  fileSlug: 'preview',
  filePathStem: '/cms/preview',
  outputFileExtension: 'html',
  templateSyntax: 'njk',
  url: '/preview/drafts.19ce8ff9-90a7-4507-b3cf-957440d170b4',
  outputPath: false // 👈
}

Removing that check when running under Serverless — leaving only the test of whether content is a string — results in placeholder replacement by the plugin transform, as expected.

@ashur ashur marked this pull request as ready for review November 25, 2023 01:02
@ashur ashur marked this pull request as draft November 27, 2023 16:44
@ashur ashur changed the title Remove page outputPath check from transform Allow missing outputPath when running under Serverless Nov 28, 2023
@ashur ashur marked this pull request as ready for review November 28, 2023 06:01
@zachleat
Copy link
Member

I think this is good! Looks like the origins of that check were to limit to .html outputs:

https://github.com/11ty/eleventy-plugin-bundle/blame/2d0b9f51bd668555fbfd80c26022a2e6d99622c8/eleventy.shortcodes.js#L55C3-L55C55

@zachleat zachleat merged commit 5d6b4f1 into 11ty:main Nov 28, 2023
@zachleat
Copy link
Member

Shipped with v1.0.5!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants