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

Can't use custom URL schemes with Photino+React #146

Closed
stevesobol opened this issue Jul 30, 2023 · 6 comments
Closed

Can't use custom URL schemes with Photino+React #146

stevesobol opened this issue Jul 30, 2023 · 6 comments
Labels
question Further information is requested Windows

Comments

@stevesobol
Copy link

As with the last issue I opened, I'm trying to fix this myself; I'm just opening this issue to document the problem.

With Photino and plain Javascript, I can register a custom URL scheme and it just works.

With React, something isn't happening. Clicking on a link with the href set to "app://blah/whatever" generates an error stating that the app: scheme isn't registered.

This is happening with the Edge Webview2 - I think. I do have the WebView2 runtime installed. I'm not 100% sure Photino's using it and I'm not sure how to check whether WebView2 is being used.

@MikeYeager MikeYeager added question Further information is requested Windows labels Aug 3, 2023
@MikeYeager
Copy link
Collaborator

Hi @stevesobol Photino does use the Evergreen version of Webview2 on Windows. We appreciate your work on this. Photino registers custom schemes prior to loading any content. We're wondering if React is trying to register the same scheme causing confusion? Out of curiosity, have you tried it on Mac or Linux? If you can share the code with us we can try it out as well. We generally do our Photino work on Thursdays btw.

@stevesobol
Copy link
Author

stevesobol commented Aug 3, 2023 via email

@stevesobol
Copy link
Author

Debian Bookworm x64/KDE works. Trying Mac next.

The problem might be Vite (probably isn't, but might be). I'm working on getting a Photino/React project to work with Vite on Windows. In addition to Mac, I'm going to create a new project (by default, Photino/React uses npm) and I'll see if I have problems with it.

One other difference: I'm using Visual Studio on the Windows PC, and VSCodium on Linux (and that's what I'll use on the Mac, too). Probably should also try using VSCodium on Windows.

(VSCodium is Visual Studio Code, but it's built without all the proprietary crap Microsoft adds, and is MIT-licensed, unlike Visual Studio Code.)

@stevesobol
Copy link
Author

The difference between my successful attempts and my unsuccessful attempts: the successful attempts used npm and straight Javascript. Creating a new project using the current React template works. With only one modification, I can load scripts using a custom script tag on any platform (I had it working on all three).

But my preferred toolchain includes Vite and TypeScript. And to get things working with my environment:

  • I had to make sure I was using the TypeScript compiler's default module-resolution scheme. (compilerOptions.moduleResolution)

  • Once I fixed that problem, the custom URL scheme still wasn't working, and the reason was... CORS! That was fixed by disabling CORS in my vite.config.js:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
    plugins: [react()],
    build: {
        outDir: './build',
        rollupOptions: {
            input: ['src/index.tsx', 'index.html'],
            external: [/^app:.*/,]
        }
    },
    server: {
        cors: false,
    },
})

Now, everything works!

This is important because create-react-app isn't supported anymore, and Vite will scaffold a simple React app for you. Plus, Vite uses Rollup, which is much faster than Webpack, which IIRC is what CRA used.

https://dev.to/ag2byte/create-react-app-is-officially-dead-h7o

We should develop a Photino.React template that uses Vite instead of CRA.

(Wait. Did I just volunteer...?)

Let's leave this issue open until I can add a link to a gist.

@MikeYeager
Copy link
Collaborator

@stevesobol We would love to see a sample!

@MikeYeager
Copy link
Collaborator

Closing due to inactivity. Please re-open if this is still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Windows
Projects
None yet
Development

No branches or pull requests

2 participants