From d9c77f2396530dca3c6930a4a4a122f7b67c3c54 Mon Sep 17 00:00:00 2001 From: Guy Ross Date: Wed, 20 Sep 2023 01:40:11 -0400 Subject: [PATCH] Fixed #158 (#159) Bug that prevented static deploy command from building components that included a react import. --- pkg/webwrap/react_ssr.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/webwrap/react_ssr.go b/pkg/webwrap/react_ssr.go index 4656ae2..90a218c 100644 --- a/pkg/webwrap/react_ssr.go +++ b/pkg/webwrap/react_ssr.go @@ -61,10 +61,19 @@ func (r *PartialWrapReactSSR) Setup(ctx context.Context, settings *BundleOpts) ( } func (r *PartialWrapReactSSR) Apply(doc jsparse.JSDocument) (jsparse.JSDocument, error) { - doc.AddImport(&jsparse.ImportDependency{ - FinalStatement: "import React from 'react'", - Type: jsparse.ModuleImportType, - }) + hasImport := false + for _, imp := range doc.Imports() { + if strings.Contains(imp.FinalStatement, "import React from 'react'") { + hasImport = true + } + } + + if !hasImport { + doc.AddImport(&jsparse.ImportDependency{ + FinalStatement: "import React from 'react'", + Type: jsparse.ModuleImportType, + }) + } doc.AddOther(fmt.Sprintf( "export default %s",