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

Difference between dev and build #11

Closed
lionelhorn opened this issue Jul 13, 2024 · 4 comments
Closed

Difference between dev and build #11

lionelhorn opened this issue Jul 13, 2024 · 4 comments

Comments

@lionelhorn
Copy link

lionelhorn commented Jul 13, 2024

Hello,

Thanks for your previous help. Continuing on my exploration:

I'm trying to use Deepkit runtime types (https://deepkit.io/documentation/runtime-types) with react-server.

In a gist, deepkit will transform the original source code to add type information so reflection and other features will be available at runtime.

// index.tsx

import "./index.css";
import {ReflectionClass} from "@deepkit/type";

export default function Index() {
  interface User {
    username: string;
    first: string;
    last: string;
    age: number;
  }

  const r = ReflectionClass.from<User>();
  const properties = r.getPropertyNames();

  return (
    <>{JSON.stringify(properties)}</>
  );
}

In dev mode, everything works. The following code (according to vite inspect plugin) gets transpiled (via a deepkit vite plugin) to

import "./index.css";
import { ReflectionClass } from "@deepkit/type";

export default function Index() {
    const __ΩUser = ['username', 'first', 'last', 'age', 'User', 'P&4!&4"&4#\'4$Mw%y'];
    const r = (ReflectionClass.from.Ω = [[() => __ΩUser, 'n!']], ReflectionClass.from());
    const properties = r.getPropertyNames();
    return (<>{JSON.stringify(properties)}</>);
}
Index.__type = ['Index', 'P"/!'];

//# sourceMappingURL=index.jsx.map

In build + start mode, code breaks and errors. The following code is built ./index.mjs

import {Fragment as t, jsx as e} from "react/jsx-runtime";
import {ReflectionClass as o} from "@deepkit/type";

function n() {
  const r = o.from().getPropertyNames();
  return e(t, {children: JSON.stringify(r)})
}

n.__type = ["Index", 'P"/!'];
export {n as default};

For instance the following line has been removed by something in the build pipeline

const __ΩUser = ['username', 'first', 'last', 'age', 'User', 'P&4!&4"&4#\'4$Mw%y'];

Any suggestions on how to troubleshoot the issue?

lionelhorn added a commit to lionelhorn/reproductions that referenced this issue Jul 13, 2024
@lionelhorn
Copy link
Author

lazarv added a commit that referenced this issue Jul 13, 2024
@lazarv
Copy link
Owner

lazarv commented Jul 13, 2024

Thanks for the repro, it was really helpful to understand how you would like to use Deepkit with the framework. Deepkit worked for me in my own repro without any issue and then checked your repro where you provided the tsConfig path directly into the plugin.

There was a missing Vite configuration flag in build that caused the vite.config.ts to be loaded multiple times and that caused to resolve the tsconfig.json differently and so it messed up the result of the Deepkit transform.

Please update to the latest version, it should work now!

You can also remove "@lazarv/react-server/types" from your tsconfig.json, it is no longer needed since a few weeks ago.

@lionelhorn
Copy link
Author

Confirmed. Working now :)

Copy link

github-actions bot commented Sep 3, 2024

This issue has been locked since it has been closed for more than 30 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest version of @lazarv/react-server. If you have any other comments you should create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants