lib/hypernova/controller_helpers.rb
##
# Modifies response.body to have all batched hypernova render results
Modifies response.body to have all batched hypernova render results
Modifies response . body to have all batched hypernova render results
def hypernova_batch_after
      @fallback = Hypernova.configuration.fallback
      if @hypernova_batch.nil?
        raise NilBatchError.new('called hypernova_batch_after without calling '\
          'hypernova_batch_before. Check your around_filter for :hypernova_render_support')
      end
      if @hypernova_batch.empty?
        return render_result_without_cache
      end
      jobs = @hypernova_batch.jobs
      hash = jobs.each_with_object({}) do |job, h|
        h[job[:name]] = job
      end
      hash = prepare_request(hash, hash)
      if send_request?(hash)
        begin
          will_send_request(hash)
          result = @hypernova_batch.submit!
          on_success(result, hash)
        rescue StandardError => e
          on_error(e)
          if @fallback
            result = @hypernova_batch.submit_fallback!
          elsif
            raise SSRError.new('Server side rendering failed due to error in code.')
          end
        end
      else
        if @fallback
          result = @hypernova_batch.submit_fallback!
        elsif
          raise SSRError.new('Server side rendering failed due to error in code.')
        end
      end
      new_body = ""
      if defined? response
        new_body = Hypernova.replace_tokens_with_result(
          response.body,
          @hypernova_batch_mapping,
          result
        )
      else
        result.each do |key, value|
          new_body += value
        end
      end
      new_body.scan(RENDER_STATUS_REGEX) do |matched|
        if matched
          render_result_without_cache
        end
      end
      if defined? response
        response.body = new_body
      else
        return new_body.html_safe
      end
    end
def hypernova_batch_after @fallback = Hypernova . configuration . fallback if @hypernova_batch . nil? raise NilBatchError . new ( 'called hypernova_batch_after without calling ' 'hypernova_batch_before. Check your around_filter for :hypernova_render_support' ) end if @hypernova_batch . empty? return render_result_without_cache end jobs = @hypernova_batch . jobs hash = jobs . each_with_object ( { } ) do | job , h | h [ job [ :name ] ] = job end hash = prepare_request ( hash , hash ) if send_request? ( hash ) begin will_send_request ( hash ) result = @hypernova_batch . submit! on_success ( result , hash ) rescue StandardError => e on_error ( e ) if @fallback result = @hypernova_batch . submit_fallback! elsif raise SSRError . new ( 'Server side rendering failed due to error in code.' ) end end else if @fallback result = @hypernova_batch . submit_fallback! elsif raise SSRError . new ( 'Server side rendering failed due to error in code.' ) end end new_body = "" if defined? response new_body = Hypernova . replace_tokens_with_result ( response . body , @hypernova_batch_mapping , result ) else result . each do | key , value | new_body += value end end new_body . scan ( RENDER_STATUS_REGEX ) do | matched | if matched render_result_without_cache end end if defined? response response . body = new_body else return new_body . html_safe end end
Modifies response.body to have all batched hypernova render results
Modifies response . body to have all batched hypernova render results
# Tell downstream not to cache when there is nothing to render. # This case happened when hypernova-ruby runs the hypernova_batch_before and hypernova_batch_after method without running # render_react_component to push the job into the list. Currently, it's known to have this behavior when render_react_component # is in a cache_when block. # Everytime when render failed (perhaps due to timeout), it will call the `BlankRenderer.render()` to render a fallback html with attribute `data-hypernova-cache` # in the first html tag. If the rendering failed, call the render_result_without_cache method to tell downstream not to cache it