Skip to content

Commit

Permalink
Fix regexp replacements for allComponents SSR (#20).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Dec 8, 2020
1 parent e9852fa commit e6c239c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ func compileSvelte(ctx *v8go.Context, SSRctx *v8go.Context, layoutPath string, d
}

// Remove allComponents object (leaving just componentSignature) for SSR.
reAllComponentsDot := regexp.MustCompile(`allComponents\.`)
ssrStr = reAllComponentsDot.ReplaceAllString(ssrStr, "")
reAllComponentsBracket := regexp.MustCompile(`allComponents\[\"?(.*)\"?\]`)
//ssrStr = reAllComponentsBracket.ReplaceAllString(ssrStr, "eval(${1})")
// Match: allComponents.layout_components_grid_svelte
reAllComponentsDot := regexp.MustCompile(`allComponents\.(layout_.*_svelte)`)
ssrStr = reAllComponentsDot.ReplaceAllString(ssrStr, "${1}")
// Match: allComponents[component]
reAllComponentsBracket := regexp.MustCompile(`allComponents\[(.*)\]`)
ssrStr = reAllComponentsBracket.ReplaceAllString(ssrStr, "globalThis[${1}]")
// Match: allComponents["layout_components_decrementer_svelte"]
reAllComponentsBracketStr := regexp.MustCompile(`allComponents\[\"(.*)\"\]`)
ssrStr = reAllComponentsBracketStr.ReplaceAllString(ssrStr, "${1}")

// Add component to context so it can be used to render HTML in data_source.go.
_, addSSRCompErr := SSRctx.RunScript(ssrStr, "create_ssr")
Expand Down

0 comments on commit e6c239c

Please sign in to comment.