Using Vue or React in Amazon MTurk's HTMLQuestion - reactjs

I want to create an MTurk HTML question that uses a modern web framework, such as Vue or React. For a minute let's assume I can't use an ExternalQuestion which just points to a website I create, but rather want to use HTMLQuestion.
Is that doable? Can I include React, for example, and it will work? Amazon's surrounding HTML will not interfere with it?

Yes, you can do this. Both HTMLQuestion and ExternalQuestion are rendered in an iframe when a worker accepts your HIT. As such, they're completely isolated from any other scripts or libraries on the surrounding page.

Related

How to set dynamic metatags in ReactJS to get nice share links?

The app
The application was made using ReactJS, React Router Dom, Styled Components and Redux ducks.
The backend we consume is also made by us using Amazon Amplify and GraphQL.
The goal
We need to define the meta tags of one of the application pages so that it is possible to share personalized links to users
in social networks using OpenGraphic meta tags and the like.
The problem
The project was made in ReactJS and ReactJS has only one HTML page as root (/public/index.html), in this way, everything is generated with Javascript in a root tag, and when it arrives in the browser it is transpiled, as we already know. The problem is that the crawlers responsible for understanding the meta tags are not able to understand Javascript and end up not finding the dynamic data that I am defining on the page that I need to share the link on. They understand that there is one html file and only.
Attempts to resolve the issue
1) Define the meta tags in the /public/index.html file itself
This solution doesn't work because the data we are using is dynamic and the index.html file is a static file
2) Using react-helmet
The solution allows meta tags to be defined, but as already mentioned, crawlers don't understand JS. So, despite being on the page, the meta tags do not appear when sharing the link.
3) Using some SSR technology
This is a possible solution, but we were unable to integrate any SSR Framework into React. And it is not feasible to change the base technology of the project. We can't just switch from React to Next, for example, as the project is already complete.
4) Using a small server made with express.js along with the React application to replace the meta tags in index.html with string.replace() simulating something like an SSR
This solution works, but it causes two requests to be made every time the page is accessed, once by express.js and once on the front-end side by React. Due to the number of requests increasing, this solution was discarded. But if necessary, you can do it. In this case it is also necessary to check if Amplify can keep the application and the small server running in the same project.
5) Using react-snap with react-helmet
React-snap allows you to create html snapshots of the pages of a React project based on their routes and links, this added to react-helmet generates a perfect solution for links to be treated well by web crawlers when they are shared. But the solution doesn't work with dynamic routes. For example, /your-route/:id is a dynamic route that expects an id to be fully defined. React-snap gets lost when trying to create a snapshot of a route that only exists when the id is set. Unfortunately, this solution doesn't work.
These were the solutions we used to try to solve the problem, but it was not possible yet. Probably attempt 4 would be the most ideal to solve the problem. But we are looking for the best way that will not generate reworks and future problems. If someone knows a better way to do that, would help us a lot!

Injecting react component into handlebars in client side

How to inject react component into handlebar template which is loading dynamically at run time.
edit: tl;dr: This is a great question. Injecting pre-rendered React components into an html templating language (like handlebars) can improve the load times of your site and improve the "indexability" of your content for search engines (your SEO). the trick is you have to server-side render (SSR) and you don't want to load all of the code into the browser on the initial request so you need code-splitting. These can be accomplished with webpack. Until recently they have not been possible without a framework like Next.js... There are now 3 options, and the conclusion I have come to is that the only one worth using is: React-Universal-Component
If you want to learn more about the benefits you get from rendering your content into HTML before the JS assets, CSS assts, etc. are loaded, this article on Isomorphic or Universal Javascript is a good place to start. Writing Isomorphic/Universal JavaScript is about writing code that is flexible in its ability to render client-side or server-side.
There are a couple if React top-level APIs that make this easy, and a handful of transpiling/compiling/bundling libraries (I use Webpack), that are necessary (if you don't want to compile the template in the browser).
Because React components are almost always written in JSX they must be transpiled to JavaScript before they can be rendered. This is typically done with ReactDOM.render() which will call React.createElement() for us.
React also has a function, ReactDOMServer.renderToString() which takes the React element, builds the HTML (on the server-side) and converts it into a string. This is what enables us to inject pre-rendered React into html templates.
For an example of the process which I have just described, see this example, but it's out of date now.
Conclusion: Injecting a React component into a handlebar template is not worth its time because there are finally libraries to help us do this (see my first link). IMO SSR React is important for sites that need the SEO benefits, and it will also improve your load times (especially on under-powered devices) if your app properly performs SSR and code-splitting.

reactjs with .jsp html templates

This is more of question of if it makes sense to use Reactjs in my instance. I have an application that generates html serverside. I can not use any js based templating solutions serverside, it is a java/jsp solution blackbox.
Since the markup is already defined I am weary of using JSX to duplicate all the template logic currently only on the serverside. What is typically the best approach to integrating reactjs in to an application like this.
What will be the real advantage to using reactjs for me in this situation. Most of may app will continue to be rendered serverside go forward.
Obviously React is not designed to be used like this; but you could still do it.
Long story short: If you want to build something more complex in front-end you should do it; if you only want to get advantage of JSX templating instead of jsp, it's just a big overhead.
Advantages:
You will be able to step away from standard jQuery approach of handling javascript in .jsp.
You will get all the benefit of a client-side framework, so you are able to handle more complex scenarios in front-end as you would do with standard javascript.
You could hide some business logic in the java side (servlets) and making it available to React world.
Disadvantages:
Probably it's a pain to prepare the development environment mode (webpack, hot-reload, etc.); e.g. you'll need to recompile the jsp on the fly on every js change.
You can't use client-side routing (so you'll have like one SPA per page).
Probably it's really hard to make server side rendering work (for the React part)

Loading external templates in react-templates during runtime?

How is it possible to load external templates from the server during runtime with react-templates (or other reacte template system)?
I can't find any doc's about it but noticed that some people mentioned it as answer in SO questions.
Or should I just implement it my self and use the function "dangerouslysetinnerhtml" to inject the html?
What I want to do?:
Store html/css snippets in xml (or json), that is produced/managed by a CMS and load these in a react app. It makes it very easy to change the html, or support different languages without changing the code and making a new deployment.
I have an app running that is doing exactly that, that I have made with Google GWT, and I want to do the same in the react app.

Use React with a non-browser JS environment

Very open ended, apologies in advance.
I've been going through the docs and searching google incessantly, but I'm wondering what steps I would need to take to use react with a non-browser JavaScript environment.
Some context on the environment:
The environment uses JavaScript to run a UI, it has http capabilities.
There is no html, css, document, window, HTMLElement, etc.
The environment does have the notion of a hierarchy, changes to the object hierarchy in JS cross the bridge and trigger a render through a graphics platform like OpenGL for instance. The environment does get input via keys and or a mouse.
If there's a roadmap to do this or something like an architecture diagram to refer to, that'd be fantastic.
Any help/advice is appreciated.
thanks in advance,
-dylan
ReactJS work with DOM, so environment need to have DOM structure, that means no HTML no DOM. Or you can use server render of React component, but you will get a string as result.
Read more here:
React.renderComponentToString

Resources