Skip to content

Commit

Permalink
fix: remove duplicate manifest imports introduced by defer work
Browse files Browse the repository at this point in the history
test: add test to assert generated scripts
  • Loading branch information
jacob-ebey committed Feb 21, 2023
1 parent 45e5a46 commit cab12ab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-bulldogs-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

remove duplicate manifest imports
29 changes: 29 additions & 0 deletions integration/link-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,33 @@ test.describe("route module link export", () => {
expect(await locator.getAttribute("imagesizes")).toBe("100vw");
});
});

test.describe("script imports", () => {
test("are added to the document", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
let scripts = await page.$$("script");
expect(scripts.length).toEqual(2);
expect(await scripts[0].innerText()).toContain("__remixContext");
let moduleScript = scripts[1];
expect(await moduleScript.getAttribute("type")).toBe("module");
let moduleScriptText = await moduleScript.innerText();
expect(
Array.from(moduleScriptText.matchAll(/import "\/build\/manifest-/g)),
"invalid build manifest"
).toHaveLength(1);
expect(
Array.from(moduleScriptText.matchAll(/import \* as route0 from "/g)),
"invalid route0"
).toHaveLength(1);
expect(
Array.from(moduleScriptText.matchAll(/import \* as route1 from "/g)),
"invalid route1"
).toHaveLength(1);
expect(
Array.from(moduleScriptText.matchAll(/import \* as route2 from "/g)),
"too many routes"
).toHaveLength(0);
});
});
});
6 changes: 3 additions & 3 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,11 @@ export function Scripts(props: ScriptProps) {

let routeModulesScript = !isStatic
? " "
: `${matches
: `import ${JSON.stringify(manifest.url)};
${matches
.map(
(match, index) =>
`import ${JSON.stringify(manifest.url)};
import * as route${index} from ${JSON.stringify(
`import * as route${index} from ${JSON.stringify(
manifest.routes[match.route.id].module
)};`
)
Expand Down

0 comments on commit cab12ab

Please sign in to comment.