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): [rendering engines] use results of exports removal if sourceMap was not generated alongside transformed code #37282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ node node_modules/gatsby/dist/schema/graphql-engine/standalone-regenerate.js
*/

import { createGraphqlEngineBundle } from "./bundle-webpack"
import { createPageSSRBundle } from "./../../utils/page-ssr-module/bundle-webpack"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes in packages/gatsby/src/schema/graphql-engine/standalone-regenerate.ts are unrelated to fix itself, just some dev tools update that I did as part of my investigation that I think make sense to commit in general - I can drop this change from this PR (and either create separate or just skip pushing it)

import reporter from "gatsby-cli/lib/reporter"
import { loadConfigAndPlugins } from "../../utils/worker/child/load-config-and-plugins"
import * as fs from "fs-extra"
import { store } from "../../redux"
import { validateEngines } from "../../utils/validate-engines"

async function run(): Promise<void> {
Expand All @@ -34,17 +36,30 @@ async function run(): Promise<void> {
console.log(`clearing webpack cache\n\n`)
// get rid of cache if it exist
await fs.remove(process.cwd() + `/.cache/webpack/query-engine`)
await fs.remove(process.cwd() + `/.cache/webpack/page-ssr`)
} catch (e) {
// eslint-disable no-empty
}

const state = store.getState()

// recompile
const buildActivityTimer = reporter.activityTimer(
`Building Rendering Engines`
)
try {
buildActivityTimer.start()
await createGraphqlEngineBundle(process.cwd(), reporter, true)
await Promise.all([
createGraphqlEngineBundle(process.cwd(), reporter, true),
createPageSSRBundle({
rootDir: process.cwd(),
components: store.getState().components,
staticQueriesByTemplate: state.staticQueriesByTemplate,
webpackCompilationHash: state.webpackCompilationHash, // we set webpackCompilationHash above
reporter,
isVerbose: state.program.verbose,
}),
])
} catch (err) {
buildActivityTimer.panic(err)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const webpackRemoveExportsLoader: LoaderDefinitionFunction<IOptions> =
(err, result) => {
if (err) {
callback(err)
} else if (result && result.code && result.map) {
callback(null, result?.code, result?.map)
} else if (result && result.code) {
callback(null, result?.code, result?.map ?? undefined)
} else {
callback(null, source, sourceMap)
}
Comment on lines -52 to 56
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actual fix here - sometimes we will get result.code with falsyt result.map, this change make sure we use that and only fallback to pass original source (and sourceMap) if transformed code is falsy or we get no result at all (not sure if that can ever happen without error)

Expand Down