Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup _main.ts generation and fix error boundary bugs #63

Merged
merged 2 commits into from
May 7, 2023
Merged

Conversation

KyleJune
Copy link
Member

@KyleJune KyleJune commented May 7, 2023

For router generation, originally I put all that logic in _main.ts. This would cause it to get very messy and hard to follow what the actual structure is from looking at it. I moved all the logic of creating the Router objects into a function named generateRouter. This makes the file a lot easier to read. Below is the _main.ts for the example in this repository.

import { generateRouter } from "x/udibo_react_app/server.tsx";

import "./main.tsx";
import * as $0 from "./main.tsx";
import $1 from "./main.ts";
import "./index.tsx";
import * as $2 from "./index.tsx";
import "./blog/main.tsx";
import * as $3 from "./blog/main.tsx";
import "./blog/index.tsx";
import * as $4 from "./blog/index.tsx";
import $5 from "./blog/index.ts";
import "./blog/[id].tsx";
import * as $6 from "./blog/[id].tsx";
import $7 from "./blog/[id].ts";
import $8 from "./api/blog/posts.ts";
import "./about.tsx";
import * as $9 from "./about.tsx";

export default generateRouter({
  name: "",
  react: true,
  main: { react: $0, oak: $1 },
  index: { react: $2 },
  children: {
    "blog": {
      name: "blog",
      react: true,
      main: { react: $3 },
      index: { react: $4, oak: $5 },
      children: {
        "[id]": { name: "[id]", react: true, file: { react: $6, oak: $7 } },
      },
    },
    "api": {
      name: "api",
      children: {
        "blog": {
          name: "blog",
          children: { "posts": { name: "posts", file: { oak: $8 } } },
        },
      },
    },
    "about": { name: "about", react: true, file: { react: $9 } },
  },
});

There was also bug in how error boundaries were automatically added to routers that resulted in the error boundary being wrong. With the logic more clearly written out in generateRouter, I was able to identify and resolve the issue.

I've also improved the readme to make it more clear how to add error boundaries to your routes.

@KyleJune
Copy link
Member Author

KyleJune commented May 7, 2023

I got the following error in CI action. This is because the stable file changed on esm.sh between versions. I didn't get a failure locally because my local cache was stale and the lock file was based on it. I fixed the issue by running deno task cache-reload, then running all the commands to update my lock files.

 error: The source code is invalid, as it does not match the expected hash in the lock file.
  Specifier: https://esm.sh/stable/[email protected]/deno/jsx-runtime.js
  Lock file: /home/runner/work/react_app/react_app/deno.lock
Error: Process completed with exit code 10.

@KyleJune KyleJune merged commit 1e802e5 into main May 7, 2023
@KyleJune KyleJune deleted the dev branch May 7, 2023 03:00
@KyleJune
Copy link
Member Author

KyleJune commented May 7, 2023

After updating, you will need to delete the _main.ts if you have one generated from a previous version of Udibo React App. Otherwise you will get an error related to it's imports preventing a new build from being saved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant