11import { ComponentType } from "react" ;
2- import { Metadata , MetroModule , Preview } from "../shared/types" ;
2+ import { Metadata , Module , Preview } from "../shared/types" ;
33import { createSignalMap } from "../utils/signal-map" ;
44import { client } from "./setup-plugin" ;
55
@@ -17,15 +17,18 @@ export function getPreviewComponents(): Preview[] {
1717}
1818
1919export function getComponentByName ( name : string ) {
20- return flattenRegistryEntries ( ) . find ( ( entry ) => entry . name === name ) ?. component || null ;
20+ return (
21+ flattenRegistryEntries ( ) . find ( ( entry ) => entry . name === name ) ?. component ||
22+ null
23+ ) ;
2124}
2225
2326/**
2427 *
2528 * @internal
2629 */
2730const __registerPreviewInternal = (
28- module : MetroModule ,
31+ module : Module ,
2932 name : string ,
3033 component : ComponentType ,
3134 metadata ?: Metadata
@@ -36,26 +39,23 @@ const __registerPreviewInternal = (
3639 module . id === undefined
3740 ) {
3841 console . warn (
39- `Cannot register preview "${ name } " in production or in non Metro environment.`
42+ `[Rozenite Preview Plugin] Cannot register preview "${ name } " in production or in non Metro environment.`
4043 ) ;
4144 return ;
4245 }
4346
4447 if ( metadata ?. isInsideReactComponent ) {
4548 console . error (
46- 'Do not call "registerPreview" inside a React lifecycle. Use it at the top level of your module.'
49+ '[Rozenite Preview Plugin] Do not call "registerPreview" inside a React lifecycle. Use it at the top level of your module.'
4750 ) ;
4851 return ;
4952 }
5053
5154 let moduleId = module . id ;
5255
53- const originalDisposeCallback = module . hot . _disposeCallback ;
54-
55- module . hot . _disposeCallback = ( ) => {
56- originalDisposeCallback ?.( ) ;
56+ module . hot . dispose ( ( ) => {
5757 registry . delete ( moduleId ) ;
58- } ;
58+ } ) ;
5959
6060 const current = registry . get ( module . id ) || [ ] ;
6161
@@ -73,8 +73,16 @@ const __registerPreviewInternal = (
7373 * @param name Preview name
7474 * @param component React component
7575 */
76- export function registerPreview ( name : string , component : React . ComponentType ) {
76+ export function registerPreview ( name : string , component : React . ComponentType ) {
77+ if ( arguments . length !== 4 ) {
78+ console . warn ( "[Rozenite Preview Plugin] Babel plugin is not configured correctly. This will result in a broken preview." ) ;
79+ return ;
80+ }
81+
7782 __registerPreviewInternal (
78- ...( arguments as unknown as [ MetroModule , string , ComponentType , Metadata ] )
83+ arguments [ 0 ] as Module ,
84+ arguments [ 1 ] as string ,
85+ arguments [ 2 ] as React . ComponentType ,
86+ arguments [ 3 ] as Metadata
7987 ) ;
8088}
0 commit comments