Skip to content

feat: add vite-7/ folder#5

Open
pzanella wants to merge 1 commit intokixelated:mainfrom
pzanella:feat/add-vite-7-folder
Open

feat: add vite-7/ folder#5
pzanella wants to merge 1 commit intokixelated:mainfrom
pzanella:feat/add-vite-7-folder

Conversation

@pzanella
Copy link

@pzanella pzanella commented Feb 4, 2026

I added a new example folder: vite-7.
This folder shows how to use @moq/hang and @moq/hang-ui with React 19 and Vite 7.
It includes a simple project setup and sample code for publishing and watching streams.

import '@moq/hang-ui/watch';
import '@moq/hang/watch/element';

interface HangWatchElement extends HTMLElement {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to get this automatically? I don't want users manually creating types.

Copy link
Author

@pzanella pzanella Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. I just opened a new PR with a specific declaration and some other fixes (I tested locally using npm pack). I tried a few different methods, but for React, separate declaration files seem to be the only solution so far. Feel free to suggest another way if you have any other ideas.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me some time to get back to you. I’ve introduced CEM (Custom Elements Manifest) to manage the different components. I believe this is a good solution to avoid type issues, generate documentation automatically, and easily create wrappers for different frameworks.
We will create wrappers for all the frameworks we want to use. As an example, in this PR, I added the React wrappers for @moq/hang and @moq/hang-ui. What do you think?
Here is an example of how the components look in React:

import { type FC } from 'react';
import '@moq/hang-ui/watch';
import '@moq/hang/watch/element';
import { HangWatchUI } from '@moq/hang-ui/react';
import { HangWatch } from '@moq/hang/react';

const HangWatchComponent: FC<{ url: string; path: string }> = ({ url, path }) => {
    return (
        <HangWatchUI>
            <HangWatch url={url} path={path} jitter={100} muted reload volume={0}>
                <canvas style={{ width: '100%', height: 'auto' }} width="1280" height="720"></canvas>
            </HangWatch>
        </HangWatchUI>
    );
};

export default HangWatchComponent;

Comment on lines +21 to +22
element.setAttribute('url', url);
element.setAttribute('path', path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should encourage using the type-safe properties, not attributes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree. I added the setters in @moq/hang specifically for this reason. This way, React and other frameworks can use type-safe properties directly via props instead of attributes.

Comment on lines +24 to +28
element.setAttribute('url', url);
element.setAttribute('path', path);
element.setAttribute('muted', '');
element.setAttribute('latency', '100');
element.setAttribute('reload', '');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, element.url should work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the setter for the url property here as well, so we don't need to use the attribute.

import react from '@vitejs/plugin-react'

// Rewrite Vite-only worklet imports inside @moq packages during transform
function moqWorkletTransform() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:/ Why is this needed?

We need to fix this if users actually have to do this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree! Unfortunately, if I remove this plugin, an error appears and the Vite dev server stops working. It seems like a compilation problem with .ts?worker&url. I'm not sure why it happens yet.

export default defineConfig({
plugins: [react(), moqWorkletTransform()],
optimizeDeps: {
exclude: ["@moq/hang", "@moq/hang-ui"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure out why this is needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree, I will investigate this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After introducing CEM, several issues were automatically resolved.
Currently, in the vite-7 folder (which I'm using for testing with npm pack), I still have this exclusion:

optimizeDeps: {
   exclude: ["@moq/hang"]
}

If I remove the optimizeDeps exclusion, I receive the following error:
image
I will look into this later.

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.

2 participants