I found the safest solution:
Set a wrapper around the sticky element to prevent layout shift.
CodeSandbox Solution