deno icon indicating copy to clipboard operation
deno copied to clipboard

Dynamic Uncached Import (Feature Request)

Open gherciu opened this issue 1 year ago • 2 comments

Starting from this issue here https://github.com/denoland/deno/issues/25742 I understood that there is a need in a dynamicUncachedImport util

After long discussions in that issue, seems that it should be a Feature request and not a Issue since it works the same on all 3 platforms Node, Deno, Bun But it would be beneficial for Deno to have it firstly

What would do dynamicUncachedImport

It will import the given module in a uncached manier, ES can do that if you add a ? query string at the end of module name, but it uncache only first level of import not nested imports inside, which may lead to bugs and is just a partiall uncache solution, it uncache only first level import not it's children imports

Where this may be used

Having such a util, we basically can implement HMR in Deno, without reloading the running process, I know Deno has --watch-hmr but most of the times it just reloads the process, and is not a programaticall thing you can't really controll it

Having it, we may build tools that allows to install plugins at runtime, wordpress like tools allowing to install themes at runtime, do server side rendering at runtime with changed JSX files

Basically What PHP world can do)) and that's why 70% of web still runs on it) because you have tools like wordpress that are famous for these features and you can change everything practically at runtime even code))


Actually the import should be cached but once a new Dynamic import happens with exact same path/name it should get the new version not one from cache

gherciu avatar Sep 20 '24 21:09 gherciu

We experienced another use-case that might benefit from some way to invalidate loaded modules.

It's related to the Deno kernel for Jupyter and using local utilities in the cells:

// utils.ts
export function log() {
  console.log('Hi!');
}

// 000-deno.ipynb
import { log } from '/app/workspace/utilts.ts';
log(); 

There's no way to reload the utils.ts without restarting the whole kernel, that could be inconvenient for large-ish notebooks with lots of data.

av avatar Oct 15 '24 14:10 av

It seems there is a lot of people claiming inconsistency with Next js hmr, wonder if it has something to do with this. Also using lume, there is no way for the server to reload tsx components due to the cached imports. Hope this get implemented.

vlermandac avatar Oct 29 '24 10:10 vlermandac

https://github.com/denoland/deno/issues/27820 would probably be resolved by this feature

kt3k avatar Jan 29 '25 05:01 kt3k

#27820 would probably be resolved by this feature

I am not sure of this. In my opinion, allows users to freely delete the import cache will have greater flexibility: Assuming that:

  • we have A1 imports B1 and C, A2 imports B2 and C, and
  • we hope that A1, B1, A2, and B2 can be Re-load, and
  • we also hope C always same (as cached import)

I am not sure if dynamicUncachedImport can do this. but you can use delete import.cache to impl dynamicUncachedImport :)

steve02081504 avatar Jan 30 '25 02:01 steve02081504

but you can use delete import.cache to impl dynamicUncachedImport :)

You can't It deletes first level of cache not it's imported modules, on next import of same files the child modules will be used from cache So no We need a method that imports thing but do not even store a cache for them, and on every next import does one from zero

gherciu avatar Jan 30 '25 07:01 gherciu