Cells seem to require all of Loading, Empty, Failure, and Success?

I can’t find it, but I thought I remembered seeing in the documentation, Github issues, or community a discussion around the required exports from a Cell just being QUERY and Success, and that if the other states weren’t defined then Success would be rendered (without data). I just created a Cell that I don’t want to have a loading state, but when I delete the Loading export I get a client error. The same thing happens if I delete Failure or Empty.

Am I misremembering? Are all 4 lifecycle functions required?

Hmm, you should be able to have a cell without them…did you try restarting your dev server just in case?

I was able to delete my Loading, Failure and Empty functions from a scaffold-generated cell and everything rendered as expected! It actually has a default Loading... message that shows that all cells inherit from the code that defines a cell: https://github.com/redwoodjs/redwood/blob/master/packages/web/src/graphql/withCell.js#L43

Interesting - I just tested and I can also delete my Loading/Failure/Empty functions and it works as expected. What I cannot do is comment them out, which is what I was doing earlier. That causes the errors I was seeing.

Is there some parser that’s just looking for those strings in the file, regardless of whether they’re commented out?

What you’re saying is correct; The webpack loader for Cells indeed just looks for the string export const <name>, no matter if it’s commented out.

I ran into this yesterday when trying to export a function instead of a const :sweat_smile:

1 Like

This sounds like a bug, so I think we have two approaches here:

Quick 'n dirty: Make the cell wrapper import all the things, and execute them if they’re defined.

Done right: Use AST

Since this is a bug, getting it working correctly would be preferable in the short term, and then making it work right would be a long term goal.