Skip to content

Commit

Permalink
inject componentRendererComponent into Remix
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrmendy committed Oct 15, 2024
1 parent c111e12 commit c605d0c
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions editor/src/components/canvas/remix/remix-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,51 @@ function getRemixExportsOfModule(
displayNoneInstances: Array<ElementPath>,
metadataContext: UiJsxCanvasContextData,
) => {
const requireFn = curriedRequireFn(innerProjectContents)
let resolvedFiles: MapLike<MapLike<any>> = {}

const customRequire = (importOrigin: string, toImport: string) =>
requireFn(importOrigin, toImport, false)
const requireFn = curriedRequireFn(innerProjectContents)
const resolve = curriedResolveFn(innerProjectContents)

const customRequire = (importOrigin: string, toImport: string) => {
if (resolvedFiles[importOrigin] == null) {
resolvedFiles[importOrigin] = []
}
let resolvedFromThisOrigin = resolvedFiles[importOrigin]

const alreadyResolved = resolvedFromThisOrigin[toImport] !== undefined
const filePathResolveResult = alreadyResolved
? left<string, string>('Already resolved')
: resolve(importOrigin, toImport)

const resolvedParseSuccess: Either<string, MapLike<any>> = attemptToResolveParsedComponents(
resolvedFromThisOrigin,
toImport,
innerProjectContents,
customRequire,
mutableContextRef,
topLevelComponentRendererComponents,
filename,
fileBlobs,
hiddenInstances,
displayNoneInstances,
metadataContext,
NO_OP,
false,
filePathResolveResult,
null,
)
return foldEither(
() => {
// We did not find a ParseSuccess, fallback to standard require Fn
return requireFn(importOrigin, toImport, false)
},
(scope) => {
// Return an artificial exports object that contains our ComponentRendererComponents
return scope
},
resolvedParseSuccess,
)
}
return createExecutionScope(
filename,
customRequire,
Expand Down

0 comments on commit c605d0c

Please sign in to comment.