Debug an Oracle JET virtual DOM app
Introduction
This tutorial shows you how to debug an Oracle JavaScript Extension Toolkit (Oracle JET) virtual DOM app using browser developer tools.
Debugging in a browser is useful to quickly isolate problematic code and to test solutions. All browsers have developer tools that you can use to perform tasks such as viewing and revising the HTML, Cascading Style Sheets (CSS), and the other source code files in your Oracle JET virtual DOM app. In addition, you can install a Preact browser extension that provides additional debugging tools in your browser’s developer tools when you debug your virtual DOM app.
Objectives
In this tutorial, you will install the Preact browser extension and learn how to use web developer tools in your browser to locate incorrect code in your Oracle JET virtual DOM app, change a supplied sample project file, and review the changes live in the browser.
Prerequisites
- A development environment set up to create Oracle JET virtual DOM apps with Node.js installed
- Google Chrome installed
- Completion of the previous tutorial in this learning path, Data Bind a Component in an Oracle JET Virtual DOM App
- The index.tsx
sample downloaded to the
JET-Virtual-DOM-app/src/components/contentdirectory
Task 1: Install Preact DevTools
An Oracle JET virtual DOM app includes, by default, the import statement to initialize a connection to Preact DevTools, a browser extension that provides additional debugging tools in Chrome DevTools. Install the Chrome browser extension that Preact provides for download at https://preactjs.github.io/preact-devtools/.
Once you have installed the extension, you’ll see a Preact tab in Chrome DevTools that provides additional tools to debug your virtual DOM app, such as a component hierarchy viewer.

Task 2: Run the Oracle JET Virtual DOM App
-
Navigate to the
JET-Virtual-DOM-app/src/components/contentdirectory, create a backup copy of yourindex.tsxfile, and then download the providedindex.tsxsample file to the same directory. -
If the Oracle JET tooling server batch job is running in the terminal window, press Ctrl+C, and if prompted, enter
yto exit the server batch job. The server batch job only recognizes revisions that you make to existing app files. After you create new files, you must run the app again. -
In the terminal window, from the
JET-Virtual-DOM-appdirectory, run the app.npx ojet serveYour browser displays the sample with a compressed chart that is not a bar or pie chart. The Select Chart dropdown list doesn’t work.

-
If your default browser isn’t Google Chrome, then open it and copy the open page’s address into the Google Chrome URL address field.
Task 3: Debug the Virtual DOM App
-
In your Google Chrome browser, right-click on the chart that appears on the page and select Inspect from the context menu that appears.
Chrome DevTools opens and displays the Elements and Styles panels that show the HTML and CSS that render your virtual DOM app.
-
In the Elements panel, select the element that begins with
<oj-chart id="barChart"and note how, in the Styles tab, below the Chart component position diagram, that the Chart componentwidthattribute reads135pixels as its value.
The
oj-chartcustom HTML element is contained by an HTMLdivelement that sets the width to135pxand causes the Chart component to look compressed on the page. Thus, the Chart component inherits its width from a parent container and ignores thewidthstyle setting of100%. -
In Chrome DevTools, press Ctrl+Shift+P and select Show Console from the menu that appears.
-
Enter the following commands to determine the values for the Select Single component’s
valueproperty and the Chart component’stypeproperty.document.getElementById("basicSelect").getProperty('value') // The Console returns 'pie' document.getElementById("barChart").getProperty('type') // The Console returns 'funnel'The Chart component’s
typeproperty value should match the value specified by the Select Single component, but it does not. -
Enter the following command to set the Chart component´s
typeproperty value topiein the browser.document.getElementById("barChart").setProperty('type', 'pie')The browser updates to display a Pie chart. This suggests that we need to examine the source code where the Chart component’s
typeproperty is set.
Task 4: Fix the Virtual DOM App Code
-
Navigate to the
JET-Virtual-DOM-app/src/stylesdirectory and open theapp.cssfile in an editor. -
If not already present, add the style class
chartStyleat the end of theappRootDir/src/css/app.cssfile..chartStyle { max-width: 500px; width: 100%; height: 350px; } -
Navigate to the
JET-Virtual-DOM-app/src/components/contentdirectory and open theindex.tsxfile in an editor. -
Search for the
oj-chartelement and remove the<div style="width:135px;">tags that surround theoj-charttag. -
Replace the
styleattribute with theclassattribute that references style properties in yourappRootDir/src/styles/app.cssfile.<oj-chart . . . style="width:100%;height:350px;">Becomes
<oj-chart . . . class="chartStyle">It is good practice to place styles that you want to apply to components in a separate CSS file rather than use the inline
styleattribute demonstrated in the previous example. -
In the
oj-chartelement, modify thetypeproperty to reference thevalvariable that theuseStatehook added instead of the hard-coded reference to thefunnelchart type.<oj-chart id="barChart" type={val} // type="funnel"Tip: If desired, add
funnelto thechartTypeDataarray that lists the types of chart in theindex.tsxfile.const chartTypeData = [ { value: "bar", label: "Bar" }, { value: "pie", label: "Pie" }, { value: "funnel", label: "Funnel" }, ]; - To verify the changes, save your file and view the updated output of the virtual DOM app in your browser.
- Replace the sample file with your original
index.tsxfile. - Close the browser window or tab that displays your running virtual DOM app.
- In the terminal window, press Ctrl+C, and, if prompted, enter
yto exit the Oracle JET tooling batch job. - Leave the terminal window open for your next tutorial.
Next Step
Proceed to the next tutorial in this module.
This tutorial is part of the module Your First Oracle JET Virtual DOM App.
- Create an Oracle JET Virtual DOM App by Using a Starter Template
- Add Components to an Oracle JET Virtual DOM App
- Data Bind a Component in an Oracle JET Virtual DOM App
- Debug an Oracle JET Virtual DOM App
- Add Unit Tests to an Oracle JET Virtual DOM App
- Prepare to Deploy an Oracle JET Virtual DOM App
You can return to the virtual DOM learning path’s main page to access all the modules on building virtual DOM apps.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.