From 4bb07f4bcebfc205692e53bb61a1e2447d589c8e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 8 Jun 2022 11:51:20 +0200 Subject: [PATCH] fix: throw on invalid island components (#224) Previously island components that didn't have a default export were just silently ignored. --- src/server/context.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/context.ts b/src/server/context.ts index ed57c35f..b8dfbfe9 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -193,12 +193,17 @@ export class ServerContext { for (const [self, module] of Object.entries(manifest.islands)) { const url = new URL(self, baseUrl).href; if (!url.startsWith(baseUrl)) { - throw new TypeError("Page is not a child of the basepath."); + throw new TypeError("Island is not a child of the basepath."); } const path = url.substring(baseUrl.length).substring("islands".length); const baseRoute = path.substring(1, path.length - extname(path).length); const name = baseRoute.replace("/", ""); const id = name.toLowerCase(); + if (typeof module.default !== "function") { + throw new TypeError( + `Islands must default export a component ('${self}').`, + ); + } islands.push({ id, name, url, component: module.default }); }