{"record":{"id":"8835445c93d1907b","repo":"nolimits4web/swiper","slug":"swiper-loop-warning-the-number-of-slides-is-not-e-883544","errorCode":null,"errorMessage":"Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)","messagePattern":"Swiper Loop Warning: The number of slides is not even to grid\\.rows, loop mode may not function properly\\. You need to add more slides \\(or make duplicates, or empty slides\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/core/loop/loopCreate.ts","lineNumber":68,"sourceCode":"      const slidesToAdd = slidesPerGroup - (swiper.slides.length % slidesPerGroup);\n      addBlankSlides(slidesToAdd);\n      swiper.recalcSlides();\n      swiper.updateSlides();\n    } else {\n      showWarning(\n        'Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)',\n      );\n    }\n\n    initSlides();\n  } else if (shouldFillGrid) {\n    if (params.loopAddBlankSlides) {\n      const slidesToAdd = params.grid!.rows! - (swiper.slides.length % params.grid!.rows!);\n      addBlankSlides(slidesToAdd);\n      swiper.recalcSlides();\n      swiper.updateSlides();\n    } else {\n      showWarning(\n        'Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)',\n      );\n    }\n    initSlides();\n  } else {\n    initSlides();\n  }\n\n  const bothDirections =\n    params.centeredSlides || !!params.slidesOffsetBefore || !!params.slidesOffsetAfter;\n  swiper.loopFix({\n    slideRealIndex,\n    direction: bothDirections ? undefined : 'next',\n    initial,\n  });\n}\n","sourceCodeStart":50,"sourceCodeEnd":85,"githubUrl":"https://github.com/nolimits4web/swiper/blob/6138c2a6857d17fe097149dd3b975b2387d0b2dc/src/core/loop/loopCreate.ts#L50-L85","documentation":"Emitted by loopCreate in the else-if (shouldFillGrid) branch at src/core/loop/loopCreate.ts:68. It fires only when grid is enabled (grid.rows > 1), the slide count is not divisible by grid.rows, and loopAddBlankSlides is false. IMPORTANT caveat grounded in the source: shouldFillGrid (slides % grid.rows !== 0) logically implies shouldFillGroup (slides % (slidesPerGroup*grid.rows) !== 0), because grid.rows divides slidesPerGroup*grid.rows. Since the first if (shouldFillGroup) branch at line 48 is checked first, this else-if is effectively unreachable when grid is enabled. A developer who sees this text most likely actually triggered error [1] (the slidesPerGroup variant) or an older build where the branch ordering differed.","triggerScenarios":"Intended trigger: { loop:true, grid:{rows:3}, loopAddBlankSlides:false } with a slide count not divisible by 3. In the current source this branch is unreachable for grid configs because shouldFillGrid implies shouldFillGroup (loopCreate.ts:34-37,48,61), so the first branch handles it and emits error [1] instead. Reachable only in a build where the order/effective divisor differs.","commonSituations":"Multi-row looping carousels built from dynamic data where the last row is incomplete; copying a grid.rows config into a looping slider; upgrading Swiper versions where loopCreate's branch logic or the slidesPerGroup*rows multiplier changed; misattributing the warning text when error [1] is what actually fired.","solutions":["Re-enable loopAddBlankSlides:true so Swiper pads the final row with blank slides (addBlankSlides at loopCreate.ts:62-66).","Add/remove slides so the count is an exact multiple of grid.rows.","Verify which warning actually fired: with grid enabled and the current source you will see error [1] (slidesPerGroup text), not this one; fix per error [1].","If blanks are unacceptable, disable loop or reduce grid.rows so the count divides evenly."],"exampleFix":"// before -- 7 slides, grid.rows 3, blanks disabled\nnew Swiper(el, { loop: true, grid: { rows: 3 }, loopAddBlankSlides: false });\n// after -- enable blank padding (default) or pad to a multiple of 3\nnew Swiper(el, { loop: true, grid: { rows: 3 }, loopAddBlankSlides: true }); // add 2 blanks -> 9","handlingStrategy":"validation","validationCode":"function loopGridWarning(slides: number, gridRows: number, loopAddBlankSlides = true): string | null {\n  if (loopAddBlankSlides) return null;\n  return slides % gridRows === 0 ? null : `slides (${slides}) not divisible by grid.rows (${gridRows})`;\n}\n// Note: in the current source this branch is unreachable for grid configs (shouldFillGroup fires first);\n// if you see this text with grid on, verify you are actually hitting error [1].\nconst msg = loopGridWarning(count, params.grid?.rows ?? 1, params.loopAddBlankSlides ?? true);","typeGuard":"function isEvenToGridRows(slides: number, gridRows: number): boolean {\n  return slides % gridRows === 0;\n}","tryCatchPattern":null,"preventionTips":["Keep loopAddBlankSlides:true so Swiper pads incomplete final rows automatically.","Ensure slide count is a multiple of grid.rows when blanks are disabled.","Be aware that with grid enabled, error [1] (slidesPerGroup text) is what normally fires; this warning's branch is effectively dead code in the current source.","Validate the grid+loop combination in isolation before wiring it into dynamic data."],"tags":["loop","grid","grid-rows","config","dead-code","loopaddblankslides"],"backgroundTag":null,"analyzedSha":"6138c2a6857d17fe097149dd3b975b2387d0b2dc","analyzedAt":"2026-08-12T21:16:10.868Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}