V7 to V8 migration guide

Go-app V8 solves the SEO critical problem by providing server-side prerendering. Unfortunately, parts of the package had to be reworked, which resulted in breaking changes.

This document is here to help to migrate V7 to V8, by enumerating things that have changed.

Import

Replace v7 imports by v8.

import (
	"github.com/maxence-charriere/go-app/v8/pkg/app"
)

Package functions

V7 V8 Description
func Run() func RunWhenOnBrowser() Starting the app on the client-side can now be called in the same code as the server-side. Build instructions and server/client code separation are not required anymore. See the Getting started article.
func Route(path string, node UI) func Route(path string, c Composer) A route can only be associated with a component now. It now associates the type of the given component rather than an instance. When navigated on, a new component is created and initialized with its zero value. Initializing component shall now be done with the Mounter interface.
func RouteWithRegexp(pattern string, node UI) func RouteWithRegexp(pattern string, c Composer) Same as Route().
func Navigate(rawurl string) - func (ctx Context) Navigate(rawURL string)
- func (ctx Context) NavigateTo(u *url.URL)
Navigating to another page is now a Context method.
func Reload() func (ctx Context) Reload() Reloading the current page is now a Context method.
func Dispatch(fn func()) - func (ctx Context) Dispatch(fn func())()
- func (c *Compo) Defer(fn func(Context))
Executing a function on the UI goroutine is now done from a Context or a Component.
func StaticResource(path string) string func (ctx Context) ResolveStaticResource(path string) string Resolving a static resource is now a Context method.
func NewContextMenu(menuItems ...MenuItemNode) Removed Context menus have been removed. This may come back eventually under another form.
func Log(format string, v ...interface{}) func Logf(format string, v ...interface{}) Log() has been renamed Logf() to match the fmt package. The new Log() function now have a similar behavior as fmt.Println().

Component interfaces

Interface V7 V8
Navigator OnNav(Context, *url.URL) OnNav(Context)
Resizer OnAppResize(Context) OnResize(Context)

Resource provider

The ResourceProvider interface has been changed:

type ResourceProvider interface {
	// Package returns the path where the package resources are located.
	Package() string

	// Static returns the path where the static resources directory (/web) is
	// located.
	Static() string

	// AppWASM returns the app.wasm file path.
	AppWASM() string
}

Concurrency

Goroutines launched from components should now be created with Context.Async(). See concurrency topic.

Report issue

Found something incorrect, a typo or have suggestions to improve this article? Let me know :)

Loading go-app documentation...