fix: json import attribute error in island (#2228)

Fixes https://github.com/denoland/fresh/issues/2214
This commit is contained in:
Marvin Hagemeister
2024-01-10 00:33:38 +01:00
committed by GitHub
parent 15929d37bd
commit 598237d5dd
7 changed files with 46 additions and 13 deletions
+4
View File
@@ -35,6 +35,7 @@ import * as $i18n_lang_lang from "./routes/i18n/[[lang]]/lang.tsx";
import * as $index from "./routes/index.tsx";
import * as $intercept from "./routes/intercept.tsx";
import * as $intercept_args from "./routes/intercept_args.tsx";
import * as $island_json from "./routes/island_json.tsx";
import * as $islands_index from "./routes/islands/index.tsx";
import * as $islands_multiple_island_exports from "./routes/islands/multiple_island_exports.tsx";
import * as $islands_returning_null from "./routes/islands/returning_null.tsx";
@@ -88,6 +89,7 @@ import * as $Foo_Bar from "./islands/Foo.Bar.tsx";
import * as $FormIsland from "./islands/FormIsland.tsx";
import * as $Greeter from "./islands/Greeter.tsx";
import * as $HookIsland from "./islands/HookIsland.tsx";
import * as $JsonIsland from "./islands/JsonIsland.tsx";
import * as $MultipleCounters from "./islands/MultipleCounters.tsx";
import * as $ReturningNull from "./islands/ReturningNull.tsx";
import * as $RootFragment from "./islands/RootFragment.tsx";
@@ -139,6 +141,7 @@ const manifest = {
"./routes/index.tsx": $index,
"./routes/intercept.tsx": $intercept,
"./routes/intercept_args.tsx": $intercept_args,
"./routes/island_json.tsx": $island_json,
"./routes/islands/index.tsx": $islands_index,
"./routes/islands/multiple_island_exports.tsx":
$islands_multiple_island_exports,
@@ -209,6 +212,7 @@ const manifest = {
"./islands/FormIsland.tsx": $FormIsland,
"./islands/Greeter.tsx": $Greeter,
"./islands/HookIsland.tsx": $HookIsland,
"./islands/JsonIsland.tsx": $JsonIsland,
"./islands/MultipleCounters.tsx": $MultipleCounters,
"./islands/ReturningNull.tsx": $ReturningNull,
"./islands/RootFragment.tsx": $RootFragment,
+5
View File
@@ -0,0 +1,5 @@
import json from "./data.json" with { type: "json" };
export default function JsonIsland() {
return <pre>{JSON.stringify(json,null, 2)}</pre>;
}
+3
View File
@@ -0,0 +1,3 @@
{
"foo": "it works"
}
+5
View File
@@ -0,0 +1,5 @@
import JsonIsland from "../islands/JsonIsland.tsx";
export default function Page() {
return <JsonIsland />;
}
+11
View File
@@ -98,6 +98,17 @@ Deno.test("island tests with </script>", async (t) => {
});
});
Deno.test("island with json import", async () => {
await withPage(async (page, address) => {
await page.goto(`${address}/island_json`, {
waitUntil: "networkidle2",
});
const json = await page.$eval("pre", (el) => el.textContent);
assertEquals(JSON.parse(json), { foo: "it works" });
});
});
Deno.test("island with fragment as root", async () => {
await withPage(async (page, address) => {
await page.goto(`${address}/islands/root_fragment`);