liferay/liferay-frontend-projects

Unable to debug React JS widget with code not minified

luizfmarins opened this issue ยท 11 comments

Issue type (mark with x)

  • ๐Ÿค” Question
  • ๐Ÿ› Bug report
  • ๐ŸŽ Feature request
  • ๐Ÿคทโ€โ™€๏ธ Other

Version (mark with x)

  • 2๏ธโƒฃ v2.x
  • 3๏ธโƒฃ v3.x
    Not sure which vesion.
    I'm using com.liferay.gradle.plugins.workspace 4.0.24 to build it.

Description

Desired behavior:
During development, I should be able to deploy a React JS widget on Chrome using the non minified code.

Current behavior:
I can debug using only the minified code

Repro instructions (if applicable):

  1. Create a new react widget using liferay new try-debug
  2. Setting NODE_ENV to development: export NODE_ENV=development
  3. Using portal-developer.properties: include-and-override=portal-developer.properties
  4. Deploy the widget to a Liferay 7.4 U54. Add to the page.
    Result:
    image (1)

Other information (environment, versions etc):
Liferay 7.4 U54
com.liferay.gradle.plugins.workspace = 4.0.24
Sample project: try-debug-fe.tar.gz
Slack thread: https://liferay.slack.com/archives/C03CAD9EF/p1677710229122429?thread_ts=1656002160.024079&cid=C03CAD9EF
Support ticket: https://liferay-support.zendesk.com/agent/tickets/82508

Mmm, don't know why, I thought this was related to a custom element CE, but it's not, of course. It's an AMD portlet. Source maps should work for custom element CEs.

Now, regarding AMD portlets, IINM, full-blown source maps have never been supported for this type of project...

Specifically, source maps will always be problematic in any AMD build because we wrap code built with a previous tool (babel, typescript, ...), that has already generated a source map, with Liferay.Loader.define, which "breaks" the source map unless we rewrite it.

Additionally, modifying a source map after it's generated is quite difficult so I think we never implemented it, but I wouldn't swear for it. I need to check in depth the source code, because I don't remember.

Can you confirm if you have seen this working before? ๐Ÿค” Thanks.

The reason why I'm doubt is because adding a single line, like Liferay.Loader.define may make rewriting the source map feasible since it is a simple offset from the original one, thus I'm not sure if we did that in the past or not, finally. I will check the source code of npm-bundler, but having a confirmation would be quite useful.

According to liferay-npm-bundler report file, this is all we run when transforming a .js file:

image

I can't see any place where we tweak the source maps generated by Babel, which makes me suspect this has never worked as requested...

I'm going to check each phase internally.

However, if the wrap-modules-amd is done by a babel plugin, I think it should work as long as we load the source map generated by the previous babel/tsc invocation and pass it to the liferay-npm-bundler phase, which I think we did some time in the past...

Apparently the first babel phase is not generating source maps.

Hi Ivan,

Can you confirm if you have seen this working before?

This is the first project I'm using @liferay/cli.
In my previous projects with Liferay 7.1 and 7.2 it used to work, but we were using the liferay-npm-bundler.

Yeah, I think this was broken with @liferay/cli for some reason...

I think this fixes it.

Hi Ivan,

I tested it and it works now.
image
Thank you very much.