Upgrading a widget
Keep a scaffolded widget current: create-grist-widget update for the SDK and the template's files, Dependabot for the rest.
A scaffold is a copy. Once npm create grist-widget has run, the widget repo
is yours and nothing in it changes by itself. What can need updating falls into
four groups:
| What | Examples | How it gets updated |
|---|---|---|
| The SDK | grist-widget-sdk, create-grist-widget (the deploy command) | create-grist-widget update: one pull request into dev |
| Other dependencies and workflow actions | React, Vite, actions/checkout | Dependabot pull requests, on dev |
| Compiler settings | what tsconfig.app.json and tsconfig.node.json extend from grist-widget-sdk | With grist-widget-sdk's own updates |
| The template's files | src/main.tsx, .github/workflows/*.yml, vite.config.ts, eslint.config.js | create-grist-widget upgrade, on dev |
| Your widget | src/app/, src/components/ui/, src/index.css, and everything else you add | Never touched, except the renamed SDK names upgrade rewrites |
SDK updates
grist-widget-sdk and create-grist-widget always share a version number,
and a new one usually brings template changes. So they move with one
command, at origin/dev:
git switch dev && git pull
pnpm exec create-grist-widget updateIt takes the newest release that is at least 7 days old, not deprecated and
no higher than npm's latest. On a branch update/create-grist-widget-<version>,
it installs exactly that version of both packages and commits, runs that
release's upgrade and commits again. Then it pushes
the branch and opens one pull request into dev (with the gh CLI),
listing what is left to change by hand.
It never adds a minimumReleaseAgeExclude entry. If a step fails, it puts
dev back as it was and drops the branch. Its options:
--dry-runsays what it would take, and changes nothing;--no-prstops after the commits;--branch <name>names the branch;--min-age-days <n>makes the wait longer than 7 days, never shorter: the wait is what keeps a compromised release from reaching the widget.
The pull request changes .github/workflows/, so pushing it needs a token
with the workflow scope.
The daily .github/workflows/sdk-update.yml tells you when to run it. In a
read-only job, it runs update --try on dev's code (the same commits, kept
local), then typecheck, lint and the tests. It opens or updates one issue
with the result, and closes it once dev is on that release or newer. An
issue you close stays closed until the next release.
GitHub runs scheduled workflows, and Dependabot reads its configuration,
from the default branch, main. In a widget that gets sdk-update.yml from
upgrade, the daily issue starts, and Dependabot's pull requests for the
two packages stop, once that change is released to main.
That text comes from running a just-published package: read it as data.
Dependabot leaves these two packages alone, its security updates included,
so that issue, with Dependabot's alerts, is their notice. GitHub turns off a
public repository's scheduled workflows after 60 days without activity:
turn it back on in the Actions tab when it says so.
Dependency updates
Every scaffold ships .github/dependabot.yml, which opens weekly pull requests
against dev:
- one grouping every other minor and patch bump,
- one per other major version (Vite and
@vitejs/*majors together, since@vitejs/plugin-reactonly builds against its own Vite major), - one for the GitHub Actions your workflows use.
TypeScript 7 is held back: typescript-eslint doesn't support it yet, so
pnpm lint would fail on every pull request proposing it.
A version is only proposed once it is a week old, which leaves time for a
broken or compromised release to be pulled. Each pull request runs
.github/workflows/ci.yml (pnpm lint, pnpm test, pnpm build), so you
know before merging whether the update breaks the widget.
Updates then follow the same loop as your own changes:
Merge the green pull request into dev. The live preview at /dev/
redeploys and self-reloads inside your open Grist document, so you can check
the update against real data.
Release it: pnpm release <patch|minor|major>
at origin/dev opens the version bump as a pull request into dev. Merge
it, then open the pull request from dev into main and merge that one.
Without the version bump nothing is published.
A few things to know:
create-grist-widgetgets a pull request of its own. Merging it updates the deploy command; the template's other files come withupgrade, which you run ondevonce it's merged.grist-widget-sdkis still 0.x, where a minor bump (0.3 → 0.4) may break things. Dependabot widens your^0.3.xrange for it, so read the SDK changelog before merging that one.- Security updates target
main. GitHub ignorestarget-branchfor them. After merging one, mergemainback intodev(git switch dev && git merge main) and release it with your next version bump. - Keep
dev. It is the permanent preview branch, and while it doesn't exist Dependabot reports an error instead of opening pull requests. - If you commit
pnpm-lock.yaml, Dependabot updates it along withpackage.json.
The template's files
The scaffold writes these and keeps them identical in every widget, so leave
them as they are: upgrade rewrites them.
src/main.tsx,src/vite-env.d.ts,src/components/theme-provider.tsx,src/lib/utils.ts.github/workflows/deploy.yml,.github/workflows/ci.yml,.github/workflows/sdk-update.yml,.github/dependabot.yml, and the rulesetsprotectapplies:.github/rulesets/main.json,.github/rulesets/dev.json,.github/rulesets/tags.jsonvite.config.ts,tsconfig.json,eslint.config.js,.prettierrc,.prettierignoreAGENTS.md,CLAUDE.md
Everything else is your widget's. Its code lives in src/app/, whose
App.tsx the template's src/main.tsx imports as the
entry module: a default export, the
widget, and its declaration, widget from defineGristWidget() (or
GRIST_OPTIONS, in a widget made before it), defined there or re-exported
from a file of its own. What the widget customises in the wiring is an export
of that file too (Alerts, LocalDevPage, ReleasePage), never an edit of
src/main.tsx. Put the widget's other files next to it, tests included: the smoke test,
src/app/App.smoke.test.tsx, is yours to extend, say with a vi.mock for a
browser API jsdom lacks. shadcn primitives stay in src/components/ui/,
where shadcn add writes them, the theme in src/index.css, and shadcn's
configuration in components.json, with any registry you add to it.
tsconfig.app.json and tsconfig.node.json take their compiler settings from
grist-widget-sdk and keep the widget's own paths and types.
Template changes
Fixes to the deploy pipeline, the build configuration or the wiring in
src/main.tsx reach a widget through create-grist-widget upgrade. It
rewrites the template's files to the copies of the create-grist-widget
version your widget depends on, and leaves the widget's own files alone.
Update create-grist-widget on dev: create-grist-widget update
does it, with the next step, in one pull request. By hand: run
pnpm update grist-widget-sdk create-grist-widget and commit.
Run the upgrade on dev, with nothing uncommitted:
pnpm exec create-grist-widget upgrade
pnpm install
pnpm typecheck && pnpm lint && pnpm test
git diffpnpm exec runs the version your widget depends on, which pnpm only
installed once it was a day old. upgrade refuses to run on main, with
uncommitted changes, or on a widget still in src/App.tsx.
It also refuses to overwrite something of the widget's own:
- a
src/main.tsxthe widget changed: it knows everysrc/main.tsxthe template has shipped (formatting aside). Move what you added intosrc/app/App.tsx(anAlerts,LocalDevPageorReleasePageexport, a provider insideApp, alazy()App), restore the template's file, and run it again; - a file of the widget's at a path a newer template starts using: move
it into
src/app/, which no template writes to.
upgrade --force overwrites them anyway.
Commit and push dev, check the /dev/ preview inside Grist, then
release as usual.
What upgrade changes:
- The template's files, each rewritten to this version's copy, or added if missing.
- Files earlier templates wrote and the current one doesn't, such as
scripts/deploy.mjsor the old landing-page components, are deleted. If one of your files still refers to one,upgradekeeps it and says which file does. tsconfig.app.jsonandtsconfig.node.json, if one doesn't extendgrist-widget-sdk's settings yet, are switched to the template's, keeping thetypesyours listed. Once they extend the SDK's, they're left alone.package.json: the template's scripts replace yours of the same name. Each template dependency is added if missing, or raised to the template's version if your range allows older ones; none is lowered or removed.createGristWidgetVersionrecords the version you upgraded to.pnpm-workspace.yaml:minimumReleaseAgeExcludeentries for versions now old enough for pnpm's age check are removed.upgradeasks the npm registry when they were published, and keeps an entry it can't check.- Renamed SDK names in your code under
src/, rewritten where the replacement means the same; the others are listed.
A template change that needs more, say in index.html (which is your
widget's), says so in the
create-grist-widget changelog,
under "Existing widgets can…". upgrade prints the link.
Renamed SDK names
grist-widget-sdk 0.7 removed the names below. upgrade rewrites your code
under src/ (the template's files aside) where the replacement means the
same:
| Before | After |
|---|---|
useGristContext() | useGrist() |
w.isReady, !w.isReady | w.status === "ready", w.status !== "ready" |
fetchTableRows(tableId, options) | fetchRows(tableId, options) |
fetchSelectedTable() | fetchRows({ columnar: true }) |
fetchTable(tableId) | fetchRows(tableId, { columnar: true }) |
import { gristAddColumnAction, … } from "grist-widget-sdk" | … from "grist-widget-sdk/actions" |
It only rewrites files that import grist-widget-sdk, and not comments.
What it can't rewrite safely it lists by file and line, to change by hand:
isAvailable (read status), a flag taken out by destructuring
(const { isReady } = w), a reader called with options, useGrist(options)
(declare the options with defineGristWidget() and call widget.useGrist()),
useGristSchema() given connection options, and renderWithGrist(ui)
without widget (in any file importing the SDK, test files included).
It also lists the names 0.8 took out of the public API, with what to do:
| Name | Instead |
|---|---|
useWidgetMetadata(…) (deprecated: still works, and warns once) | Remove the call: mountGristWidget() sets the page's title and meta tags from the declaration |
entryProps (grist-widget-sdk/app) | Pass the entry module to mountGristWidget(entry) or smokeTestWidget(entry) |
resolveMappings (grist-widget-sdk/emulator) | Read the widget's mappings with w.mappings |
enrichEmulatorColumnMetadata (grist-widget-sdk/emulator) | Nothing: createGristEmulator() completes each column's metadata |
pnpm typecheck afterwards checks the result.
Widgets declared with GRIST_OPTIONS
A widget made before create-grist-widget 0.5.0 exports GRIST_OPTIONS (and
WIDGET_METADATA) from src/app/App.tsx. It needs nothing: the 0.5.0
src/main.tsx and smoke test read either form. To get widget.useGrist()
typed with no generics, and updateRecord / addRecord typed, replace them
with one declaration, when convenient:
export const widget = defineGristWidget({ ...GRIST_OPTIONS, ...WIDGET_METADATA })then use widget.useGrist() where the widget called useGrist<TRow, TMapped>().
Widgets without create-grist-widget in their dependencies
Widgets scaffolded before the deploy command shipped in create-grist-widget
have a scripts/deploy.mjs instead, and some have no Dependabot config or
ci.yml. Add the dependency on dev, then upgrade as above: upgrade writes
the current workflows and Dependabot config, and deletes scripts/deploy.mjs.
git switch dev
pnpm add -D create-grist-widget
git commit -am "chore: depend on create-grist-widget"pnpm picks the newest version that is at least a day old. ci.yml runs
pnpm lint, pnpm test and pnpm build, so run all three after the
upgrade: a widget from an older scaffold may need a fix, or a test script,
before its first pull request can go green.
Widgets scaffolded before src/app/
Widgets used to live in src/App.tsx, next to the template's files, and
upgrade refuses to run until yours is in src/app/. Move it, with its
tests, on dev:
git switch dev
mkdir -p src/app
git mv src/App*.tsx src/app/ # App.tsx, App.test.tsx, App.smoke.test.tsx
# What they imported from src/ now goes through the @/ alias (src/ itself),
# except the tests' own import of ./App:
sed -E -i.bak -e 's#(from|import) "\./#\1 "@/#' -e 's#"@/App"#"./App"#' src/app/App*.tsx
rm src/app/*.bakIf GRIST_OPTIONS lives in a file of its own, such as src/grist-options.ts,
re-export it from src/app/App.tsx:
export { GRIST_OPTIONS } from "@/grist-options". Commit, then
upgrade: it rewrites src/main.tsx to import
./app/App, and pnpm typecheck lists any import left to fix.
The widget's other files can stay where they are. Move them into src/app/
whenever convenient, so the next template change can't collide with them.