Skip to content

fix(react): correct offset math in Background pattern - #5938

Merged
moklick merged 2 commits into
xyflow:mainfrom
Feyyus:fix/background-offset-precedence
Aug 11, 2026
Merged

moklick merged 2 commits into
xyflow:mainfrom
Feyyus:fix/background-offset-precedence

Conversation

@Feyyus

@Feyyus Feyyus commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

The scaledOffset calculation used an errant "|| 1" fallback (likely copy-pasted from the scaledGap line above, where it makes sense to floor a zero gap). Applied to offset this caused two bugs:

  • With the default offset={0}, offset*zoom is 0/falsy, so the fallback kicked in and added an extra +1px on top of the intended half-cell centering (translate(-11,-11) instead of (-10,-10) for gap={20}, zoom=1).
  • With any non-zero offset, offset*zoom is truthy, so the "||" short- circuits and the entire "+ patternDimensions/2" centering term is dropped, not just miscalculated (e.g. gap={100}, offset={2} produced translate(-2,-2) instead of the correct (-52,-52)).

Removing the fallback and just adding the two terms fixes both cases.

The scaledOffset calculation used an errant "|| 1" fallback (likely
copy-pasted from the scaledGap line above, where it makes sense to
floor a zero gap). Applied to offset this caused two bugs:

- With the default offset={0}, offset*zoom is 0/falsy, so the
  fallback kicked in and added an extra +1px on top of the intended
  half-cell centering (translate(-11,-11) instead of (-10,-10) for
  gap={20}, zoom=1).
- With any non-zero offset, offset*zoom is truthy, so the "||" short-
  circuits and the entire "+ patternDimensions/2" centering term is
  dropped, not just miscalculated (e.g. gap={100}, offset={2} produced
  translate(-2,-2) instead of the correct (-52,-52)).

Removing the fallback and just adding the two terms fixes both cases.
@changeset-bot

changeset-bot Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a0f668f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@xyflow/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hayleigh-dot-dev

Copy link
Copy Markdown
Contributor

Thanks for uconvering this @Feyyus, looks good to me! 💕

Correct miscalculation of the pattern offset in <Background /> due to an incorrect fallback in the offset math, which caused alignment issues.
@moklick
moklick merged commit e90a1b6 into xyflow:main Aug 11, 2026
@moklick moklick mentioned this pull request Aug 11, 2026
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.

3 participants