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

The preview build does not work when deployed on subpath #245

Open
timofei-iatsenko opened this issue Nov 21, 2024 · 6 comments · May be fixed by #247
Open

The preview build does not work when deployed on subpath #245

timofei-iatsenko opened this issue Nov 21, 2024 · 6 comments · May be fixed by #247

Comments

@timofei-iatsenko
Copy link

timofei-iatsenko commented Nov 21, 2024

  • Component or Package Name: jsx-email
  • Component or Package Version: 2.1.5
  • @jsxp-email/cli Version?:
  • Operating System (or Browser): MacOS., it doesn't matter
  • Node Version: v20
  • Link to reproduction (⚠️ read below):

When you deploy a preview app onto a subpath such as https://mydomain.com/emails/ it doesn't work.
The links to assets in the index.html are absolute.

So when you open https://mydomain.com/emails/ the index.html is loaded, but it tries to download assets from the root/ instead of the subpath /emails

The assets link should be relative, or there should be a way to specify a basePath for the build.

I don't know how to create a reproduction link for this, because to showcase it you need to basically deploy it somewhere.

You can reproduce it locally by following the steps:

The preview would be broken.

Also, the need to provide an absolute path for the --build-path is counterintuitive, i spend half an hour to understand where it goes when you pass relative path like --build-path ./dist/emails

For us this is important, because im trying to deploy a preview from PRs to the github pages, and it is deployed to a subpath such as https://owner.github.io/repo-name/pr-223/emails and doesn't work when served from this PR.

@shellscape
Copy link
Owner

(Note: No reproduction needed on this one since it was discussed in Discord prior)

@timofei-iatsenko
Copy link
Author

For reference: https://vite.dev/guide/build#public-base-path

Currently there is

    await viteBuild({
        ...config,
        base: '/',
       // ...
    });

I don't know is it possible to achieve it without explicit passing a base option as for vite cli

@timofei-iatsenko
Copy link
Author

Tested it with patch settings the base property to my subpath. It still doesn't work, now because of the internal router issue

@shellscape
Copy link
Owner

I've got to take a look at how it's breaking. I'll have some time this afternoon to do that, have a lot of work work to take care of this morning.

@timofei-iatsenko
Copy link
Author

Well, it seems it's not possible to implement without explicitly passing a base to the vite and router.

So the proposed solution would be to add --base parameter, which would go to vite's base property in config.

Then in the apps/preview/app/src/routes.tsx in createBrowserRouter need to specify path: import.meta.env.BASE_URL

@shellscape
Copy link
Owner

Thanks for all this info. This is next on my list to tackle.

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 a pull request may close this issue.

2 participants