-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Plugin onLoad called before onStart? #1967
Comments
Perhaps it's because
There isn't an async task in your |
Hmm, interesting. I was indeed unaware of that part of the documentation. Given those semantics, I don't think it's possible to obtain the desired behavior for this plugin using callbacks. The aim is to reset state that has been invalidated if the filesystem changed between builds. If there are no guarantees that an setup(build) {
let lastOnStartPromise
let statCache
build.onStart(() => {
lastOnStartPromise = (async () {
statCache = new cache.StatCache()
// reset other state
})()
})
build.onLoad({ filter: /\.css$/ }, async (args) => {
await lastOnStartPromise // might be undefined
// use `statCache`
})
} |
I guess maybe the following would work? setup(build) {
let statCache
async function reset() {
statCache = new StatCache()
}
let resetPromise = reset()
build.onLoad({ filter: /\.css$/ }, async (args) => {
await resetPromise
// use `statCache`
})
build.onEnd(() => {
resetPromise = reset()
})
} |
Yeah, seems like using |
Sorry about the confusing semantics. My goals were to avoid running |
If you want to retain those semantics but still provide a clean way for plugins to establish per-build state, one option that I thought of would be to introduce a property of export const cssPlugin = {
name: 'css-modules',
setup(build) {
build.onStart(async () => {
return {
statCache: new cache.StatCache(),
// ...
}
})
build.onLoad({ filter: /\.css$/ }, async (args) => {
const { statCache, ... } = await args.pluginBuildContext;
// use `statCache`
})
}
} To avoid plugins with slow |
At Figma we have a plugin with the following form:
Occasionally, our esbuild pipeline flakes with an error that includes the following:
After adding instrumentation, we found that the error happens because
statCache
is undefined. The code does not assignstatCache
anywhere other than in theonStart
callback (i.e. it does not assignundefined
to it sometime afteronStart
), so as far as I can tell, the only way this error could happen is if esbuild called this plugin'sonLoad
callback before it called theonStart
callback. (Another piece of evidence that is consistent with this explanation is that this flake always occurs on the very first .css file thatonLoad
processes.)Is it expected that
onLoad
can be called beforeonStart
?The text was updated successfully, but these errors were encountered: