From 8556658ef08ea9143b813f7cc4ee20397cc0220f Mon Sep 17 00:00:00 2001 From: Matheus Cardoso Date: Sat, 20 Jul 2024 20:00:13 -0300 Subject: [PATCH] feat(ssr): warn on host mutations during ssr --- .../@lwc/engine-server/src/utils/mutation-tracking.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/@lwc/engine-server/src/utils/mutation-tracking.ts b/packages/@lwc/engine-server/src/utils/mutation-tracking.ts index 40395c02b1..48ca657eac 100644 --- a/packages/@lwc/engine-server/src/utils/mutation-tracking.ts +++ b/packages/@lwc/engine-server/src/utils/mutation-tracking.ts @@ -12,6 +12,15 @@ const MUTATION_TRACKING_ATTRIBUTE = 'data-lwc-host-mutated'; export function reportMutation(element: HostElement, attributeName: string) { if (elementsToTrackForMutations.has(element)) { + // Add warning for host mutations during SSR + if (process.env.NODE_ENV !== 'test') { + // eslint-disable-next-line no-console + console.warn( + `Warning: Host mutation detected during SSR for attribute "${attributeName}". ` + + `This is an anti-pattern and should be avoided.` + ); + } + const existingMutationAttribute = element[HostAttributesKey].find( (attr) => attr.name === MUTATION_TRACKING_ATTRIBUTE && attr[HostNamespaceKey] === null );