DEV Community

Cover image for Shopify App - Theme Extension with React + Tailwind CSS

Shopify App - Theme Extension with React + Tailwind CSS

iskurbanov on August 03, 2023

Full course available now! πŸ‘‰ Shopify App Development Crash Course In the last few years Shopify has been revamping their App CLI and all the tooli...
Collapse
 
huykonofficial profile image
Huy Kon • Edited

After complete the cmd npm run dev, my theme editor don't show any app at contact page section, do you you know why?

Image description

Collapse
 
iskurbanov profile image
iskurbanov

You also need to run npm run deploy to create a version/draft of the extension

Collapse
 
huykonofficial profile image
Huy Kon

Hi @iskurbanov can we apply react to app embeded?

Thread Thread
 
iskurbanov profile image
iskurbanov

Yeah it’s actually the same way. You just have to create a block that will be an embed instead of app block. Just set the target to body instead of section, like this:

Image description

Thread Thread
 
huykonofficial profile image
Huy Kon

Thanks for your suggestion. it's working well. I have one more question that when we run npm run deploy it will delete all file in assets folder, I have a custom js folder in that so how can I ignore that file?

Thread Thread
 
iskurbanov profile image
iskurbanov

@huykonofficial good question, you would have to adjust the "cleanup" script in the package.json

Thread Thread
 
huykonofficial profile image
Huy Kon

@iskurbanov can you give me an example to cleanup with ignore some specific files?

Thread Thread
 
iskurbanov profile image
iskurbanov

Sorry actually it’s not because of the cleanup script. What is your custom asset called? It shouldn’t be deleting it.

Thread Thread
 
huykonofficial profile image
Huy Kon

I see that the vite build will clean up all files inside assets folder, I have my custom js for my app block or embed, it used for setting schema. So my goal I want keep these files when vite build

Thread Thread
 
iskurbanov profile image
iskurbanov

It’s only set to remove .json and .gitkeep files so your .js file shouldn’t be removed by it. Are you importing your custom js file anywhere? The Shopify build command might be removing any unused js files.

Collapse
 
clioh profile image
clioh

Hey I was interested in this course so I spun this up last night. I used the complete version from GitHub to get an idea of what the final product would look like. While the styling looks good on the preview, it does not get applied in the editor at all for some reason, which would create a confusing experience for users of the extension. Is this just a thing isolated to working on a dev branch with HMR or would it appear to a user this way once the theme app extension is published as well?

Preview in editor:
Preview in editor

As it appears on website (127.0.0.1:9292/):
Image description

Collapse
 
iskurbanov profile image
iskurbanov

Hey Clio,

Hmm that’s strange. It should work the same way. There might be an issue with the build process in your case. Did you make any changed to the code?

Iskandar

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
iskurbanov profile image
iskurbanov

Try displaying the value with liquid in the block component. Do you have that option (pickup availability) enabled in your admin dashboard?

Collapse
 
mquandtum profile image
mquandtum

I have the same issue. Once I deploy the app to heroku, I lose all tailwind styling. I've tried this on the template without altering any code or configs. The expected result is that the "Hello From React" is colored red. While running locally this is the case, but once published the text does not have the red style.

Does anyone have a solution for this?

Thread Thread
 
kylemarham profile image
Kyle Marham

Struggling with this too - Tailwind styles do not appear to be getting bundled with the output js file in the extension assets folder.

Were you able to find a fix?

Thread Thread
 
iskurbanov profile image
iskurbanov

Hey Kyle, this is the fix: github.com/iskurbanov/theme-app-ex...

Thread Thread
 
iskurbanov profile image
iskurbanov
Collapse
 
iffikhan30 profile image
Irfan

Hey @iskurbanov ,

// Handle GET request
app.get("/apps/proxy", async (_req, res) => {
console.log("GET API");
try {
console.log("trying...");
res.status(200).send({ message: "Got it" });
} catch (error) {
res.status(500).send(error.message);
}
});

When i hit the URL without shopify.validateAuthenticatedSession() it work fine, but when I call on my component

const textProxy = (d) => {
return new Promise((resolve, reject) => {
fetch("SHOP-URL/apps/proxy", {
method: 'POST',
redirect: 'manual',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify(d)
})
.then(response => {
console.log(response, 'response');
return response; // Assuming the response is in JSON format
})
.then(data => {
resolve(data);
})
.catch(error => {
reject(error);
console.log("test", error);
});
});
};

its show me 404 error, I am stuck please!

Collapse
 
nhluan profile image
Luan Nguyen

hi @iskurbanov, in the page, i added multiple this app that you guide in this article. But why don't it working to add multiple apps into sections or blocks? For example, in homepage, i want to add 2 this app into 2 sections. You can see this picture to understant about my problem. (As you see, i added 3 apps, but only one app was displeyed. Why?). Thanks @iskurbanov.
Image description

Collapse
 
iskurbanov profile image
iskurbanov

Yes I think only 1 will be displayed because we target the element by id in our react code. I haven’t had to display multiple so I’m not sure a work around this unfortunately.

Collapse
 
nhluan profile image
Luan Nguyen

I saw, thank you @iskurbanov

Collapse
 
vmhoang0306 profile image
vmhoang0306

After completed the cmd npm run dev, my terminal don't show me link to install app in step 6.
In addition, i have this error

Image description

can you help me?

Collapse
 
iskurbanov profile image
iskurbanov

Maybe you need to run "shopify login" to connect your app to your partner account.

Collapse
 
quocdatptit profile image
quocdatPTIT

Image description
Hi, after complete cmd npm run deploy, my app don't create release version, do you know why ?

Collapse
 
iskurbanov profile image
iskurbanov

What does it say in your terminal window? Any errors?

Collapse
 
quocdatptit profile image
quocdatPTIT

Image description

No error in my terminal

Thread Thread
 
iskurbanov profile image
iskurbanov

Make sure you’re deploying to the correct app in your dashboard. This one has a different name. So maybe you created 2?

Collapse
 
almusamim profile image
Hadi Zakzouk

Just wondering why you didn't go with the Hydrogen and Oxygen stack?

Collapse
 
iskurbanov profile image
iskurbanov

Hey, totally different use cases. This is for an app, Hydrogen and Oxygen are for a headless store.

Collapse
 
almusamim profile image
Hadi Zakzouk

Thanks for the reply. Sorry for my confusion :) I'm looking forward to all your Shopify courses. I hope you can do a screencast/course on Hydrogen and Oxygen stack one day as there are hardly any courses on the subject out there.

Collapse
 
markb1 profile image
Mark • Edited

Hi @iskurbanov Great article! Naming the app was the only lag in this. Much appreciated! (updated message and also LinkedIn to you - willing to hire @iskurbanov ) The app can be added as a section to any page, not just the contact page.

Collapse
 
nmy1095 profile image
Nathan Yang

Hi @iskurbanov, thanks for the detailed guide. I'm running into this error after running npm run dev. Have you encountered this before? My ruby version is ruby 3.3.3. if that's useful.

Image description

Collapse
 
jnsrst profile image
Jonas Ernst • Edited

Hi @iskurbanov
how would you integrate settings from the editor into the react code? For example i want to implement an image picker setting.

  1. Where would i put this setting?
  2. How would i get this image into the react code?

Thanks a lot!

Collapse
 
iskurbanov profile image
iskurbanov

Hey Jonas, you can easily do this by just passing them as data- attributes in the root div. Something like this:

Image description

Collapse
 
ilumin profile image
Lumin

Do you have course curriculum?

Collapse
 
notrealdev profile image
notrealdev

Hi, is there any way to transfer the newly created section to Shopify section?
Like this image?
Image description

Collapse
 
galang_ananda_c92ad3ecbc2 profile image
Galang Ananda

Getting an error after npm run dev, is there any fix ?

Image description

Collapse
 
dark_knight profile image
Harsh Arora

Can i create multiple app blocks in same extenison using react? Also how can i pass data from liquid to react app if i have some block settings?

Collapse
 
arumugasundar profile image
Arumuga Sundar Arunachalam

Hi,
I am just looking into shopify.dev/docs/apps/online-store.... Is it possible to integrate remix app as a theme extension?

Collapse
 
iskurbanov profile image
iskurbanov

Yeah probably, you would have to figure out a way to replace the vite build functionality.

Collapse
 
zain_ahmadkhan_0d921ce9a profile image
Zain Ahmad Khan • Edited

The CSS no longer applies in the sample project extension side, did Shopify change something? @iskurbanov

Collapse
 
zain_ahmadkhan_0d921ce9a profile image
Zain Ahmad Khan

Nevermind, I found the solution here
github.com/iskurbanov/theme-app-ex...