Skip to content

Add JSX view engine#132

Merged
ashquarky merged 17 commits intodevfrom
feat/jsx
Jun 25, 2025
Merged

Add JSX view engine#132
ashquarky merged 17 commits intodevfrom
feat/jsx

Conversation

@mrjvs
Copy link
Contributor

@mrjvs mrjvs commented Jun 19, 2025

changes:

  • Add JSX renderer util to response object
  • Port common partials needed for most views to JSX (web only)
  • Port messages.ejs to JSX (web only)
  • Update all (web) endpoints that use messages.ejs to use the new JSX based view

This partially contains #12


Since it may be useful for future porting, here is roughly the steps I took to port EJS to JSX:

  1. Make a new component for the new view
  2. Copy paste the old EJS code into new view
  3. Replace EJS conditionals and loops with JSX (conditional: { cond ? < /> : < />}, loops: { arr.map(v => (< />)})
  4. Close all selfclosing tags (<img src="..."> -> <img src="..." />)
  5. Replace class attributes with className
  6. Replace style="" attributes with style={{}} (jsx takes an object and not a string)
  7. Replace dynamic text content with JSX style: <% hi %> -> {hi}
  8. Replace dynamic attributes with JSX version: src="<%cdnUrl%>/test.png" -> src={\${cdnUrl}/test.png``
  9. Update all standard HTML attributes (stroke-width) to camelcase (strokeWidth) - exclude custom attributes that aren't standard
  10. Raw style tag content and script tag content can be set using a new util: InlineScript and InlineStyle

Some more caveats:

  • There are no globals from res.locals. So I made a context object to passs around and put all of that in.
  • Partials don't exist, simply make a new component
  • While this PR does include React, we're only using the JSX tools. This system only generates HTML with 0 javascript, so state or reactivity or contexts, it all doesn't work. It can only generate static HTML.

@mrjvs mrjvs requested a review from ashquarky June 19, 2025 16:52
@mrjvs mrjvs marked this pull request as ready for review June 21, 2025 13:48
@mrjvs mrjvs marked this pull request as draft June 21, 2025 15:12
@mrjvs
Copy link
Contributor Author

mrjvs commented Jun 21, 2025

Back to draft, since the JSX view now diplays on 3ds and wiiu as well. It should get a different template for each

@mrjvs mrjvs marked this pull request as ready for review June 22, 2025 10:46
@mrjvs
Copy link
Contributor Author

mrjvs commented Jun 22, 2025

I updated the code to render all the different consoles/directories. Also tested all 3 of them, they seem to be working

Copy link
Member

@ashquarky ashquarky left a comment

Choose a reason for hiding this comment

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

Good stuff all around. Just a few design thoughts and one note on how to get strong typing

@ashquarky
Copy link
Member

Also worth noting that our ESLint config doesn't seem to cover TSX/JSX files. I guess https://www.npmjs.com/package/@pretendonetwork/eslint-config needs updating to match the new file extensions

@mrjvs
Copy link
Contributor Author

mrjvs commented Jun 24, 2025

@ashquarky I have addressed all review comments. Also added made an eslint config PR but we don't have to wait for it imo.

@mrjvs mrjvs requested a review from ashquarky June 24, 2025 19:17
Copy link
Member

@binaryoverload binaryoverload left a comment

Choose a reason for hiding this comment

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

PretendoNetwork/common-configs#3 is merged, update pls :)

@mrjvs
Copy link
Contributor Author

mrjvs commented Jun 24, 2025

Eslint now updated, although it still has one linting bug that will be fixed in a different PR :P

Copy link
Member

@ashquarky ashquarky left a comment

Choose a reason for hiding this comment

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

Wow, eslint made the code aesthetics way worse! ^^

Looks good though, awesome

@ashquarky ashquarky merged commit 477c758 into dev Jun 25, 2025
13 checks passed
@ashquarky ashquarky deleted the feat/jsx branch June 25, 2025 05:49
@ashquarky
Copy link
Member

Each child in a list should have a unique "key" prop.

Check the render method of `WebMessagesView`. See https://react.dev/link/warning-keys for more information.
[15:51:49.663] INFO (100287): request completed
    req: GET juxt.pretendo.network/friend_messages (::ffff:172.18.0.6:47692)
    res: 200 (5740 bytes)
    responseTime: 37

Anything to worry about?

@mrjvs
Copy link
Contributor Author

mrjvs commented Jun 25, 2025

Nothing to worry about since that has to do with reactivity engine, which we don't use and can't use.

Although it's a bit sloppy to leave it there indefinitely, I'll fix it next time I work on Jsx related tasks

@mrjvs mrjvs mentioned this pull request Jun 25, 2025
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.

3 participants