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

fix(gatsby-source-contentful): Improve base64 placeholders #29034

Merged
merged 4 commits into from
Jan 15, 2021

Conversation

axe312ger
Copy link
Collaborator

@axe312ger axe312ger commented Jan 14, 2021

This replaces the no more maintained base64-img package with a more native implementation.

Additionally it fixes the following bug:

This should fix the security vulnerabilities from #24679

@axe312ger axe312ger added the status: needs core review Currently awaiting review from Core team member label Jan 14, 2021
@axe312ger axe312ger requested a review from ascorbic January 14, 2021 17:31
@axe312ger axe312ger self-assigned this Jan 14, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 14, 2021
@axe312ger axe312ger changed the title Perf/contentful better lqip base64 Contentful: Improve base64 placeholders Jan 14, 2021
@axe312ger axe312ger force-pushed the perf/contentful-better-lqip-base64 branch from 29746c1 to d529588 Compare January 15, 2021 09:05
@axe312ger axe312ger added topic: source-contentful Related to Gatsby's integration with Contentful and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 15, 2021
)
reject(e)
})
const promise = new Promise(async (resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a need to wrap this all in a Promise. It's an async function so it returns a promise anyway, and you can just await the fs-extra calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need the promise for the caching layer. Otherwise I'd have removed it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but async fucntions return promises anyway, so no need to wrap it like you've done.

Copy link
Contributor

Choose a reason for hiding this comment

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

async function loadImage() {

..then:

const promise = loadImage()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well yeah I can make a small function that is called. I tried not to alter the code structure to much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ascorbic done

const body = `data:image/jpeg;base64,${base64}`

// TODO: against dogma, confirm whether writeFileSync is indeed slower
fs.promises
Copy link
Contributor

Choose a reason for hiding this comment

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

You have fs-extra in the project which promisifies all of the fs calls, so you can just use that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But why go fs-extra if we have it supported in the language?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member topic: source-contentful Related to Gatsby's integration with Contentful
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants