Skip to content

Commit 8b99fb3

Browse files
AyoubElkairhorns
authored andcommitted
update plugin to allow returning a unique symbol identifying a registered route
1 parent 57bcea9 commit 8b99fb3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/fastify-renderer/src/node/Plugin.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface FastifyRendererOptions {
2222
hooks?: (FastifyRendererHook | (() => FastifyRendererHook))[]
2323
}
2424

25+
export type RegisteredRenderable = symbol
26+
2527
export class FastifyRendererPlugin {
2628
renderer: Renderer
2729
devMode: boolean
@@ -34,6 +36,7 @@ export class FastifyRendererPlugin {
3436
clientManifest?: ViteClientManifest
3537
serverEntrypointManifest?: ServerEntrypointManifest
3638
routes: RenderableRoute[] = []
39+
registeredComponents: Record<RegisteredRenderable, RenderableRoute> = {}
3740

3841
constructor(incomingOptions: FastifyRendererOptions) {
3942
this.devMode = incomingOptions.devMode ?? process.env.NODE_ENV != 'production'
@@ -105,7 +108,13 @@ export class FastifyRendererPlugin {
105108
}
106109
}
107110

108-
registerRoute(options: RenderableRoute) {
111+
registerRoute(options: RenderableRoute): RegisteredRenderable {
112+
// If the component is not already registered, we register it and return a unique symbol for it
113+
const symbol = Symbol(options.renderable)
114+
this.registeredComponents[symbol] = options
115+
109116
this.routes.push(options)
117+
118+
return symbol
110119
}
111120
}

0 commit comments

Comments
 (0)