Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Fix SSR for event pages
Dave Earley7e822bfbc566
diff --git a/backend/app/Resources/Event/EventResourcePublic.php b/backend/app/Resources/Event/EventResourcePublic.phpindex 1b83db2c9..cda988b84 100644--- a/backend/app/Resources/Event/EventResourcePublic.php+++ b/backend/app/Resources/Event/EventResourcePublic.php@@ -2,12 +2,13 @@namespace HiEvents\Resources\Event;-use Illuminate\Http\Request;use HiEvents\DomainObjects\EventDomainObject;use HiEvents\Resources\BaseResource;use HiEvents\Resources\Image\ImageResource;+use HiEvents\Resources\Organizer\OrganizerResourcePublic;use HiEvents\Resources\Question\QuestionResource;use HiEvents\Resources\Ticket\TicketResourcePublic;+use Illuminate\Http\Request;/*** @mixin EventDomainObject@@ -50,6 +51,10 @@ class EventResourcePublic extends BaseResource!is_null($this->getImages()),fn() => ImageResource::collection($this->getImages())),+ 'organizer' => $this->when(+ !is_null($this->getOrganizer()),+ fn() => new OrganizerResourcePublic($this->getOrganizer()),+ ),];}}diff --git a/backend/app/Resources/Organizer/OrganizerResourcePublic.php b/backend/app/Resources/Organizer/OrganizerResourcePublic.phpnew file mode 100644index 000000000..97cac8203--- /dev/null+++ b/backend/app/Resources/Organizer/OrganizerResourcePublic.php@@ -0,0 +1,27 @@+<?php++namespace HiEvents\Resources\Organizer;++use HiEvents\DomainObjects\OrganizerDomainObject;+use HiEvents\Resources\Image\ImageResource;+use Illuminate\Http\Resources\Json\JsonResource;++/**+ * @mixin OrganizerDomainObject+ */+class OrganizerResourcePublic extends JsonResource+{+ public function toArray($request): array+ {+ return [+ 'id' => $this->getId(),+ 'name' => $this->getName(),+ 'website' => $this->getWebsite(),+ 'description' => $this->getDescription(),+ 'images' => $this->when(+ (bool)$this->getImages(),+ fn() => ImageResource::collection($this->getImages())+ ),+ ];+ }+}diff --git a/backend/app/Services/Handlers/Event/GetPublicEventHandler.php b/backend/app/Services/Handlers/Event/GetPublicEventHandler.phpindex 35315a1bb..92f1a178b 100644--- a/backend/app/Services/Handlers/Event/GetPublicEventHandler.php+++ b/backend/app/Services/Handlers/Event/GetPublicEventHandler.php@@ -6,6 +6,7 @@ use HiEvents\DomainObjects\EventDomainObject;use HiEvents\DomainObjects\EventSettingDomainObject;use HiEvents\DomainObjects\Generated\PromoCodeDomainObjectAbstract;use HiEvents\DomainObjects\ImageDomainObject;+use HiEvents\DomainObjects\OrganizerDomainObject;use HiEvents\DomainObjects\TaxAndFeesDomainObject;use HiEvents\DomainObjects\TicketDomainObject;use HiEvents\DomainObjects\TicketPriceDomainObject;@@ -38,6 +39,7 @@ readonly class GetPublicEventHandler)->loadRelation(new Relationship(EventSettingDomainObject::class))->loadRelation(new Relationship(ImageDomainObject::class))+ ->loadRelation(new Relationship(OrganizerDomainObject::class, name: 'organizer'))->findById($data->eventId);$promoCodeDomainObject = $this->promoCodeRepository->findFirstWhere([diff --git a/backend/config/jwt.php b/backend/config/jwt.phpindex f4f3fa32f..6970e79af 100644--- a/backend/config/jwt.php+++ b/backend/config/jwt.php@@ -89,7 +89,7 @@ return [|*/- 'ttl' => env('JWT_TTL', 60 * 48),+ 'ttl' => env('JWT_TTL', 60 * 24 * 7),/*|--------------------------------------------------------------------------diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 48a3f19c8..6f6066024 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -33,7 +33,7 @@ export const App: FC<> = (props) => {const [isLoadedOnBrowser, setIsLoadedOnBrowser] = React.useState(false);const localeActivated = useRef(false);- const [loaded, setLoaded] = useState(false);+ const [loaded, setLoaded] = useState(isSsr());useEffect(() => {if (!localeActivated.current && typeof window !== "undefined") {diff --git a/frontend/src/components/common/EventDocumentHead/index.tsx b/frontend/src/components/common/EventDocumentHead/index.tsxindex 1a63eb8e2..6bf6df1d4 100644--- a/frontend/src/components/common/EventDocumentHead/index.tsx+++ b/frontend/src/components/common/EventDocumentHead/index.tsx@@ -18,14 +18,13 @@ export const EventDocumentHead = ({event}: EventDocumentHeadProps) => {const startDate = utcToTz(new Date(event.start_date), event.timezone);const endDate = event.end_date ? utcToTz(new Date(event.end_date), event.timezone) : undefined;- // Dynamically build the address object based on available dataconst address = {- "@type": "PostalAddress",- streetAddress: event.location_details?.address_line_1,- addressLocality: event.location_details?.city,- addressRegion: event.location_details?.state_or_region,- postalCode: event.location_details?.zip_or_postal_code,- addressCountry: event.location_details?.country+ "@type": "http://schema.org/PostalAddress",+ streetAddress: eventSettings?.location_details?.address_line_1,+ addressLocality: eventSettings?.location_details?.city,+ addressRegion: eventSettings?.location_details?.state_or_region,+ postalCode: eventSettings?.location_details?.zip_or_postal_code,+ addressCountry: eventSettings?.location_details?.country};// Filter out undefined address properties@@ -33,15 +32,15 @@ export const EventDocumentHead = ({event}: EventDocumentHeadProps) => {// @ts-ignoreObject.keys(address).forEach(key => address[key] === undefined && delete address[key]);- const location = event.location_details && Object.keys(address).length > 1 ? {- "@type": "Place",+ const location = eventSettings?.location_details && Object.keys(address).length > 1 ? {+ "@type": "http://schema.org/Place",name: event.location_details?.venue_name,address} : {};const schemaOrgJSONLD = {"@context": "http://schema.org",- "@type": "Event",+ "@type": "http://schema.org/Event",name: title,startDate,endDate,@@ -50,19 +49,21 @@ export const EventDocumentHead = ({event}: EventDocumentHeadProps) => {description: description,keywords,organizer: {- "@type": "Organization",+ "@type": "http://schema.org/Organization",name: event.organizer?.name,url: event.organizer?.website},url,+ eventStatus: 'https://schema.org/EventScheduled',eventAttendanceMode: event.settings?.is_online_event ? "https://schema.org/OnlineEventAttendanceMode" : "https://schema.org/OfflineEventAttendanceMode",currency: event.currency,offers: event.tickets?.map(ticket => ({- "@type": "Offer",+ "@type": "http://schema.org/Offer",url,- price: ticket.price?.toString(),+ price: ticket.prices?.[0]?.price,priceCurrency: event.currency,- validFrom: startDate+ validFrom: startDate,+ availability: ticket.is_available ? "http://schema.org/InStock" : "http://schema.org/SoldOut",})),};diff --git a/frontend/src/entry.client.tsx b/frontend/src/entry.client.tsxindex 795c55e8d..d408d80f3 100644--- a/frontend/src/entry.client.tsx+++ b/frontend/src/entry.client.tsx@@ -18,47 +18,34 @@ if (window.__REHYDRATED_STATE__) {}async function initClientApp() {- if (window.__REHYDRATED_STATE__) {- // Determine if any of the initial routes are lazy- const lazyMatches = matchRoutes(router, window.location)?.filter(- (m) => m.route.lazy- );-- // Load the lazy matches and update the routes before creating your router- // so we can hydrate the SSR-rendered content synchronously- if (lazyMatches && lazyMatches?.length > 0) {- await Promise.all(- lazyMatches.map(async (m) => {- const routeModule = await m.route.lazy?.();- Object.assign(m.route, {...routeModule, lazy: undefined});- })- );- }-- const browserRouter = createBrowserRouter(router);-- ReactDOM.hydrateRoot(- document.getElementById("app") as HTMLElement,- <App- queryClient={queryClient}- locale={getClientLocale()}- >- <RouterProvider router={browserRouter} fallbackElement={null}/>- </App>- );- } else {- ReactDOM.createRoot(document.getElementById("app") as HTMLElement).render(- <App- queryClient={queryClient}- locale={getClientLocale()}- >- <RouterProvider- router={createBrowserRouter(router)}- fallbackElement={null}- />- </App>+ // Determine if any of the initial routes are lazy+ const lazyMatches = matchRoutes(router, window.location)?.filter(+ (m) => m.route.lazy+ );++ // Load the lazy matches and update the routes before creating your router+ // so we can hydrate the SSR-rendered content synchronously+ if (lazyMatches && lazyMatches?.length > 0) {+ await Promise.all(+ lazyMatches.map(async (m) => {+ const routeModule = await m.route.lazy?.();+ Object.assign(m.route, {...routeModule, lazy: undefined});+ }));}++ // todo - Investigate using hydrateRoot instead of createRoot+ ReactDOM.createRoot(document.getElementById("app") as HTMLElement).render(+ <App+ queryClient={queryClient}+ locale={getClientLocale()}+ >+ <RouterProvider+ router={createBrowserRouter(router)}+ fallbackElement={null}+ />+ </App>+ );}initClientApp();diff --git a/frontend/src/entry.server.tsx b/frontend/src/entry.server.tsxindex b4641aabb..2987cceab 100644--- a/frontend/src/entry.server.tsx+++ b/frontend/src/entry.server.tsx@@ -43,7 +43,6 @@ export async function render(params: {<StaticRouterProviderrouter={routerWithContext}context={context}- nonce="the-nonce"/></App>);