Skip to content
Gx
GitHub

GX4012: c.Update takes a component with no fragment

A hint. An action gives c.Update a component that has no fragment and many dynamic values, so the server sends the whole component for each change.

Cause

GX4012 is a hint. It does not fail gx check.

c.Update sends the fragments of a component that changed. A fragment is the unit of an update. A component with no fragment has one unit: its root. The server then sends the whole component for each change.

Gx gives the hint for a component with more than 8 dynamic values.

Example

board/route/route.go
package route

import "github.com/alternayte/gx"

type Refresh struct {
	gx.Route `POST /board/refresh`
}
board/Board.gx
package board

props {
  Open   int
  Closed int
  Late   int
  Today  int
  Week   int
  Month  int
  Owner  string
  Team   string
  Note   string
}

<table id="board">
  <tr><td>{p.Open}</td><td>{p.Closed}</td><td>{p.Late}</td></tr>
  <tr><td>{p.Today}</td><td>{p.Week}</td><td>{p.Month}</td></tr>
  <tr><td>{p.Owner}</td><td>{p.Team}</td><td>{p.Note}</td></tr>
</table>
board/board.go
package board

import (
	"github.com/alternayte/gx"
	"app/board/route"
)

var refresh = gx.Action(func(c *gx.Ctx, in route.Refresh) error {
	return c.Update(Board(BoardProps{Open: 3, Closed: 9}))
})

var Routes = gx.Collect(refresh)

gx check reports:

gx check
board/board.go:9:9: GX4012: hint: c.Update takes the component "Board", which has no fragment and 9 dynamic values: the server sends the whole component for each change. Mark the parts that change with #name

Fix

  1. Mark each part that changes with a fragment name: <td #open>{p.Open}</td>.
  2. Or keep the component as it is. The update is correct; it sends more bytes.
  3. For one exact target, use c.Patch with the fragment function.