I have an LWC on a community which is working perfectly outside of the community but when ran on the community to pull the recordId from the url, it tries the wire with the initial blank value, then after it pulls in the recordId it isn't running the wire reactive again. It seems to work on my sandbox as it can find the record quick enough to not fail the first time, but in production it seems to take a little too long to grab the recordId from the URL. I also tried doing it manually with getters and setters but to no avail.
I have done all field and object importing above the copied code but as explained above, all is working outside of the community so I do not believe it to be at fault.
JS
const fields = [FIELD1,FIELD2];
export default class userLWC extends NavigationMixin(LightningElement) {
@api recordId;
@track isSpinner = false;
connectedCallback() {
this.isSpinner = true;
}
@wire(getRecord, { recordId: '$recordId', fields })
handleWiredRecord(result){
this.record = result;
console.log('result==>'+result);
const {error,data} = result;
if (error){
this.dispatchEvent(new ShowToastEvent({
title: 'Error loading Record',
message: error.body.message,
variant: 'error'
}),);
console.warn(error);
} else if (data){
this.isSpinner = false;
console.log('data==>'+data);
this.record = data;
}
}
HTML
<template>
<template if:true={isSpinner}>
<div class="spinner">
<lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner>
</div>
</template>
<lightning-card title="Test">
<template if:false={isSpinner}>
<div class="slds-var-m-around_medium">
<div class="slds-float_right">
Meta
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Test Component</masterLabel>
<description>Test Component.</description>
<targets>
<target>lightning__RecordPage</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
<targetConfigs>
<targetConfig targets="lightningCommunity__Default">
<property name="recordId" type="String" label="Record ID" description="Should be set to {!recordId}" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>