verbb / smith

A Craft CMS plugin to add copy, paste and clone functionality to Matrix blocks.
MIT License
25 stars 9 forks source link

Duplicating unsaved matrix block fails #17

Closed Joorren closed 3 years ago

Joorren commented 3 years ago

Description When you try to duplicate a matrix block that has not been saved yet since creation, a javascript occurs and the block isn't duplicated.

Uncaught TypeError: t.blocks.filter is not a function
    at s.constructor.filterBlocks (smith.js:299)
    at smith.js:325
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:315)
    at smith.js:325
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:315)
    at smith.js:325
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:315)

Steps to reproduce

  1. Create new matrix block and don't save the entry
  2. Duplicate the matrix block

Additional info

Additional context MatrixMate plugin is installed.

engram-design commented 3 years ago

Pretty sure this is a MatrixMate issue, as I can't replicate this on a fresh install without it. Would you be able to test if this is still an issue, after the fix in https://github.com/verbb/smith/issues/18 ?

Joorren commented 3 years ago

Sorry for the late response, I've been really busy and didn't have time to test this before.

I still seem to get the same error as above:

Uncaught TypeError: t.blocks.filter is not a function
    at s.constructor.filterBlocks (smith.js:291)
    at smith.js:317
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:307)
    at smith.js:317
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:307)
    at smith.js:317
    at Array.forEach (<anonymous>)
    at s.constructor.filterBlocks (smith.js:307)
engram-design commented 3 years ago

Hmmm, I can't seem to replicate how you've got that exact error I'm afraid. But I have added guards against it. To get the fix early, change your verbb/smith requirement in composer.json to:

"require": {
  "verbb/smith": "dev-craft-3 as 1.1.14",
  "...": "..."
}

Then run composer update.

Joorren commented 3 years ago

The guards you added seem to solve the problem! Thanks for looking into it 😄