Skip to content

Create Devtools package and its Roblox plugin #14

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jeparlefrancais
Copy link
Collaborator

@jeparlefrancais jeparlefrancais commented Sep 15, 2023

This PR sets up a Roblox plugin that re-implements the React developer extension

We cannot use the existing extensions (like the chrome or firefox extensions) because Roblox does not have a socket API, so it cannot communicate with them. That is why I built this plugin.

The goal was to get the profiler working, so the "components" tab is not implemented.

Notes

  • this is a very experimental plugin
  • the flamegraph view does not translate super well into Roblox, so I've made an attempt at something that looks alright
  • so far, I tested this on a minuscule React tree, I have not idea what it looks like on some real React project. I expect the flamegraph to look particularly funny
  • to view the changes in a commit, open the settings and hit the button to enable changes recording, it is disabled by default
  • settings are not saved (annoying a little because if you want commit changes you have to enable them all the time) but they could definitely be
  • the plugin only works in Run mode, so it will show up after you press the 'Play' button. It could be made to also work in edit mode, it will just need a different setup (and proper reloading capability)

How to test it out

You will need the plugin and a few modification in your code before you render your root.

Build the plugin

rojo build packages/roblox-devtools-plugin -o react-lua-devtools.rbxm

Roblox setup

Here is an example of how to setup the devtools inside Roblox:

-- make sure to set the `__PROFILE__` global to true
_G.__PROFILE__ = true
_G.__DEV__ = true

local Packages = ...

-- require the ReactDevtools package
local _ReactDevTools = require(Packages.ReactDevtools)

local React = require(Packages.React)
local ReactRoblox = require(Packages.ReactRoblox)

-- I have not fully figured out how to make sure everything is properly wired so that 
-- the devtools are properly hooked up because rendering, so it appears that some 
-- kind of delay is needed for the extension to properly work
task.wait(1)

local container = Instance.new("Folder")
container.Name = "ReactContainer"
container.Parent = script.Parent.Parent.PlayerGui

local root = ReactRoblox.createRoot(container)

-- render your component here!
root:render(React.createElement(YourComponent))

Screenshot of the extension

image

Copy link
Collaborator

@matthargett matthargett left a comment

Choose a reason for hiding this comment

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

Minor comments. Great work!

@jeparlefrancais jeparlefrancais changed the title Translate WhatChanged component and its dependencies Create Devtools package and its Roblox plugin Sep 22, 2023
return
end

if runModes.edit then

Choose a reason for hiding this comment

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

Not good, I essentially make my entire game in Hoarcekat--I need it there!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep! For now I want to disable it to prevent any confusion about the plugin not working in edit mode.

It's definitely possible to make it work though, the plugin would just need to make sure to re-connect and clean up the connections correctly.

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