nuxt-remote-fn
nuxt-remote-fn copied to clipboard
Can't use the same filename twice in the project
Using the same filename twice in the project leads to this
// .nuxt/remote-handler.ts
import * as todo from '.../feature-A/todo.server'
import * as todo from '.../feature-B/todo.server'
export type RemoteFunction = {
todo: typeof todo
todo: typeof todo
}
export default createRemoteFnHandler({
todo,
todo
})
Which breaks the module
I propose using the full (relative) path to the file when extracting the module id
// current
expect(getModuleId('/src/feature-A/todo.server.ts')).toBe('todo')
// proposed
expect(getModuleId('/src/feature-A/todo.server.ts')).toBe('feature_A__todo')
The path would be relative the source directory: nuxt.options.srcDir
A double underscore should be enough to avoid accidental duplicates, though it could be a configuration option
Cons of this approach:
-
createClient
becomes more verbose, specially with deeply nested files - Deeply nested files could also make really long urls
- Exposes project structure to the frontend (probably not an issue)
- Breaking change if
createClient
is already used