Back to LinkedIn posts

LinkedIn post 102

I've recreated this diagram inspired by Philippe Ozil's article about LWC Inter-Com...

I've recreated this diagram inspired by Philippe Ozil's article about LWC Inter-Component Communication Patterns. ๐Ÿ™

๐Ÿ”— LINK: https://lnkd.in/g8VdKJ5H

Some thoughts, trying to go beyond what is in the article:

๐Ÿ‘‰ passing objects via @api results in read-only proxies sent to children - this might affect data flows and debugging and we will have to copy/clone them before making changes.

๐Ÿ‘‰ Lightning Message Service's default sends messages only within the active tab - for utility bar + primary tab we need scope APPLICATION_SCOPE in subscribe()

๐Ÿ‘‰ LMS or Pub/Sub leaves the dependency between LWCs implicit, thus making harder to refactor or trace data flows and might increase complexity.

๐Ÿ‘‰ Pub/Sub requires manual unregistration of listeners in disconnectedCallback() to avoid memory leaks - LMS will require unregistering only if using createMessageContext() or if references are kept.

๐Ÿ‘‰ Public methods don't trigger auto-rerender - careful if calling a method before the child has rendered - you may have to check the sequence of connected and rendered callback events.

๐Ÿ‘‰ Custom events might require deeper awareness of DOM event phases if needing interception/capture.

๐Ÿ‘‰ LMS and Pub/Sub are fire-and-forget, no queueing or guaranteed delivery - subscriber might not be yet rendered or connected when the message is published - you might need ack messages or state checks.

Other pertinent links:
๐Ÿ”— Step Up Your LWC Skills โ€“ Part 1
https://lnkd.in/gjw5KK9s
๐Ÿ”— Define the Scope of the Message Service
https://lnkd.in/g6x_RMQx
๐Ÿ”— Lightning Message Service Limitations
https://lnkd.in/g3gmcfPS
๐Ÿ”— lightning/messageService https://lnkd.in/g8Vfg8rT

Thanks to Sarabjeet Pal who pointed out we now have State Managers as another communication alternative between parent and child LWCs! ๐Ÿ™
๐Ÿ”— https://lnkd.in/gEMwBvu3

diagram