Skip to content

feat(theme-check-common): two checks for range setting structural validity#1202

Open
hyldmo wants to merge 1 commit into
Shopify:mainfrom
hyldmo:feat/valid-range-default
Open

feat(theme-check-common): two checks for range setting structural validity#1202
hyldmo wants to merge 1 commit into
Shopify:mainfrom
hyldmo:feat/valid-range-default

Conversation

@hyldmo
Copy link
Copy Markdown

@hyldmo hyldmo commented May 11, 2026

Adds two checks for range setting structural validity, both mirroring the dual-export pattern from #1185 (ValidSelectDefault).

ValidRangeDefault

Today you can write a range setting whose default lies outside [min, max] or off the min + n*step grid, e.g.

{ "type": "range", "min": 0, "max": 160, "step": 8, "default": 60 }

shopify theme push accepts it. shopify theme dev and the theme editor reject it with:

Invalid schema: setting with id="…" default must be a step in the range

which is a hard 500 on the entire local theme server, not a per-section warning.

ValidRangeStepCount

Same class of bug for Shopify's 101-step ceiling:

{ "type": "range", "min": 0, "max": 200, "step": 1 }

Storefront error:

Invalid schema: setting with id="…" step invalid. Range settings must have at most 101 steps

Step count is (max − min) / step + 1; the check suggests the smallest step that fits within 101.

Coverage

Surface ValidRangeDefault ValidRangeStepCount
settings[i].default n/a
presets[i].settings n/a
Section default.settings n/a
Range setting definition (min/max/step) n/a
config/settings_schema.json

ValidRangeStepCount is intentionally setting-definition-only — the 101-step limit applies to the range's own min/max/step, not to preset/default values (which are covered by ValidRangeDefault).

Severity

ERROR for both — these are hard runtime failures that crash theme dev, not stylistic concerns.

Float handling

1e-9 tolerance so step: 0.1, default: 4.7 and similar fractional ranges don't false-positive. Suggested replacement values (nearest valid step, or minimum step that fits within 101) are included in the messages.

Tests

28 new tests; full theme-check-common suite (974 tests / 102 files) passes.

Why

This footgun comes up regularly in real-world theme repos — shopify theme push and the CLI's theme-check both accept these schemas, but the storefront/theme-editor parser rejects them at render time, taking down the entire local theme dev server. Catching it statically would save a class of "CI green, local crashes" reports.

Adds two checks for `range` setting structural validity, mirroring the
dual-export pattern from Shopify#1185 (ValidSelectDefault):

- ValidRangeDefault: errors when a range setting's default value is
  outside [min, max] or not aligned to the (min + n*step) grid. Covers
  setting defaults, presets[].settings, section default.settings, and
  config/settings_schema.json.

- ValidRangeStepCount: errors when a range setting has more than 101
  discrete steps. Covers the setting definition and
  config/settings_schema.json.

Both surface as hard 'Invalid schema' errors during `shopify theme dev`
and in the theme editor, but `shopify theme push` accepts them
silently — making this a common footgun where CI passes but the local
theme dev server crashes on every render.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hyldmo hyldmo requested a review from a team as a code owner May 11, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant