-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
alternative approach to #77 for ssr reload detection #83
Conversation
I'm not sure it will simplify things. It might, but not necessarily. We would still need to track dependencies. The worries about race conditions is the really tricky part and they wouldn't go away. They might become worse by having another event (the watcher firing) happening asynchronously. Once the watcher triggers, can we guarantee that Snowpack will immediately respond with the new version of the file, or is there a risk of still getting the old version for a short period? Ideally, I'd like to see some kind of "if modified since" API for snowpack so that we could just ask directly "has this file changed?" rather than hashing it and comparing to the cache. |
Dependencies are tracked, that's what this line does: graph.get(pathname).add(importer); I'm not sure I understand the concerns about race conditions? Can you describe a situation in which this might break?
Yes
There is no more hashing in this PR! |
Sorry, I somehow thought this was an issue and not a PR, so I never saw the code and thought you were talking about an abstract idea. No, this is of course lower complexity than my suggestion. I see two possible race conditions in this code:
Another thing that strikes me: this assumes that the module structure is the same as the file structure. Is that always the case? E.g. symbolic links, directory aliases and preprocessing |
0c2aa66
to
a5d2db2
Compare
Happy to expose an API for this, and I'd actually recommend that you use it. Not just to remove the need for two file watchers, but also because Snowpack plugins have the ability to respond to file changes, and can potentially mark other files as changed. See https://www.snowpack.dev/guides/plugins#onchange() and https://www.snowpack.dev/guides/plugins#this.markchanged() Sass is our best illustration of this, where a change to a helper file like I'll probably go ahead and add this to Snowpack via PR regardless, but it is up to you all to use it or not! |
It looks like this is the new API that @FredKSchott suggested he might add that we can use here: FredKSchott/snowpack#1452 |
Nice! I tried switching to the new API in #130 and it seems to work. |
I'l close this in favor of #130 since using the new API seems like a sensible way to go. Feel free to reopen this if you disagree with that Rich |
I'm not quite sure what happened with #130. It looks like it was merged into this branch, so I'm reopening this PR so that we can get the change into |
@Rich-Harris can you drop |
using snowpack.onFileChange
c5f594d
to
652767c
Compare
This is an alternative approach to #77 — rather than comparing a module and all its dependencies to the cache to determine whether it's stale, we use a filewatcher to proactively evict files from the cache as necessary.
I'd argue it's a bit simpler (allows us to ditch the
hash
stuff altogether), and more closely resembles what Snowpack itself is doing. Thoughts @ehrencrona?cc @FredKSchott — maybe there'd be some value in exposing an API for this?
(Though if there's any plan to eventually bake the loading logic into Snowpack itself, then there'd be no need to expose an invalidation API, so this might be premature.)