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

esbuild chunking solution breaks after commit 3903815 #111

Closed
weilandia opened this issue Sep 14, 2022 · 10 comments
Closed

esbuild chunking solution breaks after commit 3903815 #111

weilandia opened this issue Sep 14, 2022 · 10 comments

Comments

@weilandia
Copy link

#100 3903815 breaks chunking with esbuild when implemented as suggested here: #48

The reason is likely do the the fact that esbuild creates static chunks that do not have names, i.e. chunk-123, chunk-456, etc.

This is discussed here: evanw/esbuild#1716

@weilandia
Copy link
Author

After 3903815:

Screen Shot 2022-09-14 at 3 18 20 PM

@brenogazzola
Copy link
Collaborator

Thanks for the report. I have a large app running esbuild and propshaft, so I’ll apply chunking to it and see what I can do to fix this.

@brenogazzola
Copy link
Collaborator

brenogazzola commented Sep 24, 2022

@weilandia I can't seem to replicate the problem. I've created a demo app and configured it for esbuild, chunknames, and a lazy import (file named async.js). It worked fine

Do you have a demo app showing the problem? If not, could you take a look at mine and indicated what I'm missing when trying to replicate?

Screen Shot 2022-09-24 at 14 06 34

@weilandia
Copy link
Author

weilandia commented Sep 28, 2022

I can't recreate the issue with your app. If you add something like the below, you'll see the dynamic chunk file being added, but still no issue.

// a.js
import { d } from "./c.js"
console.log('a', d)
import("./b.js")
// b.js
import { c } from "./c.js"
console.log('b', c)
// c.js
export const c = 1
export const d = 2

Our app results in 76 of these chunk-... files and about 75% of them result in 404s AFTER #3903815 but works fine before. I'll plan to dig into it more next week.

@weilandia
Copy link
Author

Closing this because we decided not to do chunking with esbuild, though I do think there is a hard to reproduce issue when using propshaft with esbuild chunking on large apps (after 3903815).

@firien
Copy link

firien commented Nov 13, 2022

also running into this issue. @weilandia were you using anything like chunkNames: 'chunks/[name]-[hash].digested' in esbuild options? If so, all the chunks resolve to the same chunks/chunk.js path and asset.fresh? fails in

if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)

image

@firien
Copy link

firien commented Nov 13, 2022

@brenogazzola - the "issue" is that esbuild creates many files named chunk-[hash] and propshaft will resolve that to 1 logical path: chunk.js

@weilandia - You can work around this by ensuring unique chunk names by including the hash in the "logical" part of the file name too:

chunkNames: 'chunks/[name][hash]-[hash].digested'

@brenogazzola
Copy link
Collaborator

I'm reviewing the esbuild docs and it seems there's no option to name the chunk anything other than chunk. It seems the only solution might be reverting #100 at this point.

@rainerborene Any thoughts on this? Is there another way we can get propshaft to ensure the preloads still work without breaking esbuild chunks, which always have the same name?

@firien
Copy link

firien commented Nov 14, 2022

@brenogazzola, while not ideal - you can get esbuild to output unique chunks if you include the hash twice #111 (comment)

chunkNames: 'chunks/[name][hash]-[hash].digested'


I am testing propshaft (main branch & digested assets) & esbuild on a rails 7 upgrade and I have chunks loading, source maps loading (#117) - I have not yet got around to testing when esbuild updates a file and gets a new hash - whereby you have more than one "digested" file and propshaft should find the latest version

@strobilomyces
Copy link

Dealing with this after the 0.7.0 release. firien's fix works, but given that chunks/[name]-[hash] is the standard example in the esbuild docs, I expect a fair number of people are going to end up here, wondering what happened. If there's no good way to fix this in propshaft, I'd say it would be worth documenting the above fix (and maybe printing a warning when the gem is updated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants